When I click in edit button it gives me a error, what is problem I can not understand now, please help me
Trying to get property 'id' of non-object (View: C:\xampp\htdocs\ytl\resources\views\profile\edit.blade.php)
This is my userprofilecontroller
public function edit( Request $request, $id){
$user_profile_id = UserProfile::where('id', '=', $id)->firstOrFail();
$exchanges = Exchange::pluck('exchange','id')->all();
$markets = Market::pluck('market','id')->all();
$countries = Country::pluck('country','id')->all();
$brokerage_company = BrokerageCompany::pluck ('brokerage_company','id')->all();
$user_profile = UserProfile::pluck('charge_intraday','charge_delivery','charge_per_lot','charge_per_order')->all();
return view('profile.edit', compact('user_profile_id','exchanges','markets','countries','brokerage_company','user_profile'));
}
public function update(Request $request, $id){
$user_profile_id = UserProfile::findOrFail($id);
$input = $request->except( 'brokerage_company','user_profile');
$user_id = $user_profile->update($input);
return redirect('/profile');
}
This is profile\index.blade.php file
<div class="card card-table">
<div class="card-header">Basic Tables
<div class="tools dropdown"><span class="icon mdi mdi-download"></span><a class="dropdown-toggle" href="#" role="button" data-toggle="dropdown"><span class="icon mdi mdi-more-vert"></span></a>
<div class="dropdown-menu" role="menu"><a class="dropdown-item" href="#">Action</a><a class="dropdown-item" href="#">Another action</a><a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div><a class="dropdown-item" href="#">Separated link</a>
</div>
</div>
</div>
<div class="card-body">
<table class="table">
<thead>
<tr>
<th style="width:10%;">Country</th>
<th style="width:10%;">Exchange</th>
<th class="number">Market</th>
<th class="number">Company</th>
<th class="actions">Charges</th>
</tr>
</thead>
#if($user_profile)
<tbody>
#foreach($user_profile as $user_profiles)
<tr>
<td>{{$user_profiles->country->country}}</td>
<td>{{$user_profiles->exchange->exchange}}</td>
<td>{{$user_profiles->market->market}}</td>
<td>{{$user_profiles->brokerage_company->brokerage_company}}</td>
<td class="cell-detail"><span>Intaday-charge</span>{{$user_profiles->charge_intraday}}
<span class="cell-detail-description">Delivery-charge</span>
{{$user_profiles->charge_delivery}}</td>
{{--<td>{{$user_profiles->charge_per_lot}}</td>--}}
{{--<td>{{$user_profiles->charge__per_order}} </td>--}}
<td> <a class="btn btn-info btn-sm" href="{{route('profile.edit', $user_profiles->id)}}">Edit</a></td>
</tr>
#endforeach
</tbody>
#endif
</table>
</div>
</div>
This is profile\edit.blade.php file
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add Charge</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
{{--<form method="PATCH", id="form", action="{{action('Profile\UserProfileController#update',$user_profile_id->id)}} ", accept-charset="UTF-8">--}}
{{--{{ csrf_field() }}--}}
{{--{{ method_field('PATCH') }}--}}
{!! Form::model($user_profile,['method'=>'PATCH', 'action'=> ['Profile\UserProfileController#update',$user_profile->id]]) !!}
<div class="row">
<div class="col-md-6 mb-3 form-group">
Country:<select name="country_id" id="country" class="form-control " onchange="myfunc()" >
<option value="">Select</option>
#foreach($countries as $key=>$val )
<option value="{{ $val->id }}">{{ $val->country }}</option>
#endforeach
</select>
</div>
<div class="col-md-6 mb-3 form-group">
Exchange:<select name="exchange_id" id="exchange" class="form-control notselect" onchange="myfunc1()">
<option value="">Select</option>
{{--#foreach($exchanges as $key=>$val )--}}
{{--<option value="{{ $val->id }}">{{ $val->exchange }}</option>--}}
{{--#endforeach--}}
</select>
</div>
<div class="col-md-6 mb-3 form-group">
Market<select name="market_id" id="market" class="form-control bindselect" >
<option value="">Select</option>
{{--#foreach($markets as $key=>$val )--}}
{{--<option value="{{ $val->id }}">{{ $val->market }}</option>--}}
{{--#endforeach--}}
</select>
</div>
<div class="col-md-6 mb-3 form-group">
Company:<select name="brokerage_company_id" id="brokerage_company_id" class="form-control " >
<option value="">Select</option>
#foreach($brokerage_company as $key=>$val)
<option value="{{ $val->id }}">{{ $val->brokerage_company }}</option>
#endforeach
</select>
</div>
<div class="col-md-6 mb-3 form-group">
Intraday_charge: <input type="text" name="charge_intraday" class="form-control"><br>
</div>
<div class="col-md-6 mb-3 form-group">
Delivery_charge: <input type="text" name="charge_delivery" class="form-control"><br>
</div>
<div class="col-md-6 mb-3 form-group">
Delivery_charge: <input type="text" name="charge_per_lot" class="form-control"><br>
</div>
<div class="col-md-6 mb-3 form-group">
Delivery_charge: <input type="text" name="charge_per_order" class="form-control"><br>
</div>
{!! Form::close() !!}
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" value="Submit" name="form1" class="btn btn-primary">Save changes</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
It seems like you misunderstood the Pluck method. Pluck is to take several properties out an array by their key. Nothing to do with selecting columns from a Database.
I guess you want to select a single UserProfile. And the right way of doing this is as follows:
public function edit(Request $request, $id){
$user_profile = UserProfile::findOrFail($id); // Select a UserProfile by ID or fail
$exchanges = Exchange::all('exchange', 'id');
$markets = Market::all('market','id');
$countries = Country::all('country','id');
$brokerage_company = BrokerageCompany::all ('brokerage_company','id');
// I dont know what you want with this statement?
// $user_profile = UserProfile::pluck('charge_intraday','charge_delivery','charge_per_lot','charge_per_order')->all();
return view('profile.edit', compact('user_profile','exchanges','markets','countries','brokerage_company'));
}
Related
in laravel 9 i have tables
team (columns are team_name, igl_name, match_id)
tournament
match_id
and tour_team is table (colums are team_id, tournamnet_id and match_id)
in the option I am retrieving match id in value now I want to update this match id with match_id in tour_team, table which is pivot table for that for specific team. and tournament
here is form
<form action="" method="POST">
<div class="form-group">
<div class="form-control-wrap">
<select name="match_id" class="js-select" id="tax-class" data-sort="false">
<option value="">Select an option</option>
#foreach ($matches as $mate)
<option value="{{$mate->id}}">{{$mate->name}}</option>
#endforeach
</select>
</div>
</div>
<button type="submit">Update Match</button>
</form>
Here is complete code of team
#foreach ($team as $item)
#if ($item->pivot->match_id == 0)
<tr style="background-color: #dddddd;">
<td class="tb-col">
<div class="media-group">
<div class="media media-md flex-shrink-0 media-middle media-circle">
<img src="images/product/a.jpg" alt="">
</div>
<div class="media-text">
{{ $item->team_name }}
</div>
</div>
</td>
<td class="tb-col">
<div class="media-group">
<div class="media media-md flex-shrink-0 media-middle media-circle">
<img src="images/product/a.jpg" alt="">
</div>
<div class="media-text">
{{ $item->igl_name }}
<span class="text smaller">{{ $item->igl_id }}</span>
</div>
</div>
</td>
<td class="tb-col tb">
<form action="" method="POST">
<div class="form-group">
<div class="form-control-wrap">
<select name="match_id" class="js-select" id="tax-class" data-sort="false">
<option value="">Select an option</option>
#foreach ($matches as $mate)
<option value="{{$mate->id}}">{{$mate->name}}</option>
#endforeach
</select>
</div>
</div>
<button type="submit">Update Match</button>
</form>
</td>
<td>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#example-{{ $item->id }}">
<em class="icon fa fa-users"></em>
</button>
<!-- Modal -->
<div class="modal fade" id="example-{{ $item->id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalScrollableTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-scrollable" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalScrollableTitle">{{ $item->team_name }}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
#foreach ($item->members as $members)
<div class="media-group">
<div class="media media-md flex-shrink-0 media-middle media-circle">
<img src="images/product/a.jpg" alt="">
</div>
<div class="media-text">
{{ $members->player_name }}
<span class="text smaller">{{ $members->player_id }}</span>
</div>
</div>
#endforeach
</div>
</td>
<td>
<button type="button" class="btn btn-color-primary btn-hover-primary btn-icon"><i class="fa-solid fa-ban"></i></button>
</td>
</tr>
#endif
#endforeach
want to update id in pivot table in laravel9
Here I am doing l laravel CRUD operation.
I have a table named scores.
Schema::create('scores', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('match_id');
$table->unsignedBigInteger('team_id');
$table->unsignedBigInteger('player_id');
$table->unsignedBigInteger('scoreupdate_id');
$table->unsignedBigInteger('outby_id');
$table->timestamps();
$table->foreign('match_id')->references('id')->on('matchhs')->onDelete('cascade');
$table->foreign('team_id')->references('id')->on('teams')->onDelete('cascade');
$table->foreign('player_id')->references('id')->on('players')->onDelete('cascade');
$table->foreign('scoreupdate_id')->references('id')->on('scoreupdates')->onDelete('cascade');
$table->foreign('outby_id')->references('id')->on('scoreupdates')->onDelete('cascade');
});
Where I want to store data from the different tables so I did this with my Score.php model
class Score extends Model
{
use HasFactory;
use HasFactory;
protected $fillable =['team_id','match_id','player_id','scoreupdate_id','outby_id','out_type',
'one','two','three','four','six'];
public function team(){
return $this->belongsTo(Team::class,'team_id');
}
public function matchh(){
return $this->belongsTo(Matchh::class,'match_id');
}
public function player(){
return $this->belongsTo(Player::class,'player_id');
}
public function scoreupdate(){
return $this->belongsTo(Scoreupdate::class,'scoreupdate_id');
}
}
And This to my ScoreController.php
public function index()
{
$data=Score::all();
$team=Team::all();
$match=Matchh::all();
$player=Player::all();
$scoreupdate=Scoreupdate::all();
return view('admin.manage.score.index',compact('data','team','match','player','scoreupdate'));
}
public function store(Request $request)
{
Score::insert([
'match_id' => $request->match_id,
'team_id' => $request->team_id,
'player_id' => $request->player_id,
'scoreupdate_id' => $request->scoreupdate_id,
'outby_id' => $request->outby_id,
]);
$notification = array('message'=>'Scoreupdate Inserted!','alert-type'=>'success');
return redirect()->back()->with($notification);
}
And This is my index.blade.php
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0">Score</h1>
</div><!-- /.col -->
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#teamModal">
+ Add New
</button>
</ol>
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container-fluid -->
</div>
<!-- Main content -->
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">All score list here</h3>
</div>
<!-- /.card-header -->
{{-- card body --}}
<div class="card-body">
<table id="example1" class="table table-bordered table-striped table-sm">
<thead>
<tr>
<th>SL</th>
<th>Match Name</th>
<th>Team Name</th>
<th>Player Name</th>
<th>Out type</th>
<th>Out by type</th>
<th>Action</th>
</tr>
</thead>
<tbody>
#foreach ($data as $key => $row)
<tr>
<td>{{ $key + 1 }}</td>
<td>{{ $row->matchh->match_name }}</td>
<td>{{ $row->team->team_name }}</td>
<td>{{ $row->player->player_name }}</td>
<td>{{ $row->scoreupdate->out_type }}</td>
<td>{{ $row->scoreupdate->out_by_type }}</td>
<td>
<a href="#" class="btn btn-info btn-sm edit"
data-id="{{ $row->id }}" data-toggle="modal"
data-target="#editModal"><i class="fas fa-edit"></i></a>
<a href="{{ route('score.delete', $row->id) }}"
class="btn btn-danger btn-sm" id="delete"><i
class="fas fa-trash"></a>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<!-- /.card-body -->
</div>
</div>
</div>
</div>
</section>
</div>
{{-- insert modal --}}
<!-- Modal -->
<div class="modal fade" id="teamModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add Player Modal</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="{{ route('score.store') }}" method="Post">
#csrf
<div class="modal-body">
<div class="from-group">
<label for="player_name">Match Name</label>
<select class="form-control" name="match_id" required="">
#foreach ($match as $row)
<option value="{{ $row->id }}">{{ $row->match_name }}</option>
#endforeach
</select>
</div>
<div class="from-group">
<label for="player_name">Team Name</label>
<select class="form-control" name="team_id" required="">
#foreach ($team as $row)
<option value="{{ $row->id }}">{{ $row->team_name }}</option>
#endforeach
</select>
</div>
<div class="from-group">
<label for="player_name">Player Name</label>
<select class="form-control" name="player_id" required="">
#foreach ($player as $row)
<option value="{{ $row->id }}">{{ $row->player_name }}</option>
#endforeach
</select>
</div>
<div class="from-group">
<label for="out type">Out type</label>
<select class="form-control" name="scoreupdate_id" required="">
#foreach ($scoreupdate as $row)
<option value="{{ $row->id }}">{{ $row->out_type }}</option>
#endforeach
</select>
</div>
<div class="from-group">
<label for="out by type">Out by type</label>
<select class="form-control" name="outby_id" required="">
#foreach ($scoreupdate as $row)
<option value="{{ $row->id }}">{{ $row->out_by_type }}</option>
#endforeach
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
<button type="Submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
</div>
The problem is that when I add not out in my out type box which is id(1) in scoreupdates table and add caught in my out by type box which is id(2) of my scoreupdates table
It's inserting and retrieving not out and (-) where both of them hold id(1) of scoreupdates table but I want that when I insert not out it will insert and retrieve not out and when add caught it will insert and retrieve caught.
scores table database
I think this could be wrong you are doing
<td>{{ $row->scoreupdate->out_type }}</td
<td>{{ $row->scoreupdate->out_by_type }}</td>
On both column, you are trying to retrieve data from scoreUpdate, but looking at your database it looks like they are two foreign columns and it should be some other relation from relation outby_id, not scoreupdate_id.
On model, its showing,
public function scoreupdate(){
return $this->belongsTo(Scoreupdate::class,'scoreupdate_id');
}
It's retriving data from scoreupdate_id not outby_id
hello i need to do an update inside a model using Laravel, the problem is when i click on the update button (his name in the code is Modifier) the page is not refreshing.
i have tried to work with an a tag in place of button .and with the a tag the page refresh but my data is not updating.
can someone tell me where is the problem in the code
the index view code :
<table class="table table-bordered table-left">
<thead>
<tr>
<th>#</th>
<th>Nom</th>
<th>Email</th>
<th>Rôle</th>
<th>Action</th>
</tr>
</thead>
<tbody>
#foreach ($users as $key=>$user)
<tr>
<td>{{ $key+1 }}</td>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td>
#if ($user->is_admin==1)Administrateur
#else Caissier
#endif
</td>
<td>
<div class="btn-group">
<a class="btn btn-success" href="" data-toggle="modal" data-target="#edituser{{ $user->id }}">
<i class="fas fa-edit"></i>
</a>
<a href="" class="btn btn-danger">
<i class="fas fa-trash"></i>
</a>
</div>
</td>
</tr>
{{-- edit model --}}
<div class="modal right fade" id="edituser{{ $user->id }}" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="staticBackdropLabel">Modifier l'utilisateur</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="{{ route('users.update', $user->id) }}" method="post">
#csrf
#method('put')
<div class="form-group">
<label for="name">Nom</label>
<input type="text" value="{{ $user->name }}" name="name" class="form-control">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" value="{{ $user->email }}" name="email" class="form-control">
</div>
<div class="form-group">
<label for="name">Mot de passe</label>
<input type="password" readonly name="password" value="{{ $user->password }}" class="form-control">
</div>
{{-- <div class="form-group">
<label for="name">Confirmer le mot de passe</label>
<input type="password" name="confirm_password" class="form-control">
</div> --}}
<div class="form-group">
<label for="name">Rôle</label>
<select name="is_admin" id="" class="form-control">
<option value="1" #if ($user->is_admin==1)
selected
#endif>Administrateur</option>
<option value="2" #if ($user->is_admin==2)
selected
#endif>Caissier</option>
</select>
</div>
<div >
<button class="btn btn-success btn-block">Modifier</button>
</div>
</form>
</div>
</div>
</div>
</div>
#endforeach
</tbody>
</table>
the controller code :
public function update(Request $request, $id)
{
$users = User::find($id);
if (!$users) {
return back()->with('Error','user created');
}
$users->update($request->all());
return back()->with('Success','user created');
}
Your button
<button class="btn btn-success btn-block">Modifier</button>,
should be
<button class="btn btn-success btn-block" type="submit">Modifier</button> in order to submit the form to your controller.
I need to update some columns from my DB using the modal... question is how do I pass the data from the Modal to the Controller#update? I can get dynamic data to the Modal, but the form action does not appear to function. Can someone help me? I'm getting really frustrated by this.
=( here is my code, that is generating the modal according:
//route
Route::resource('/dashboard', 'DashboardController');
//DashboardController.php
public function index(Request $request)
{
$equipments = Equipments::all();
$serviceProviders = ServiceProviders::all();
$engineers = Engineers::all();
$equipmentsDue = Equipments::Where('due1', '<>', '1990-01-01')
->orderBy($due1)
->get();
$customerSite = CustomerSites::all();
return view('dashboard.index', compact('sort', 'customerSite', 'equipmentsDue', 'serviceProviders', 'engineers'));
}
// /dashboard/index.blade.php
#foreach ($equipmentsDue as $equipment)
<!------modal -->
<div class="modal fade" id="myModal-{{ $equipment->id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Next Due</h4>
</div>
<div class="modal-body">
<form class="app-form" id="modal-form" action="/dashboard/update/{{ $equipment->id }}" method="POST">
{{ csrf_field() }}
<div class="form-group">
<label for="title">Next Due*</label>
<input type="text" class="form-control" id="datepicker1" name="due1" placeholder="Next Due">
</div>
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<label for="title">Completed By:</label>
<!-- Service Provider -->
<select name="note1" class="form-control" id="note1">
#foreach ($serviceProviders as $serviceProvider)
<option value="{{ $serviceProvider->id }}">{{ $serviceProvider->name }}</option>
#endforeach
</select>
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<!-- Engineer -->
<label for="title">Engineer</label>
<select name="note2" class="form-control" id="note2">
#foreach ($engineers as $engineer)
<option value="{{ $engineer->id }}">{{ $engineer->name }}</option>
#endforeach
</select>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-xs-12">
<label for="title">Comments:</label>
<textarea name="note3" class="form-control" id="note3" placeholder="comments"></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-default" data-dismiss="modal">Save</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- modal ends-->
<tr class="alert-danger">
<td><input type="checkbox"></td>
<td align="center">{{ date("d-m-Y", strtotime($equipement->due1)) }}</td>
<td align="center"><button type="button" class="btn btn-danger btn-xs">TMU</button></td>
<td>{{ $equipment->CustomerSites->customer->name . " -> " . $equipment->CustomerSites->sitename }}</td>
<td>{{ $equipment->CustomerSites->SiteRegions->name }}</td>
<td>{{ $equipment->sn }}</td>
<td>{{ $equipment->cap }}</td>
<td></td>
<td><button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#myModal-{{ $equipment->id}}">COMPLETE</button></td>
</tr>
#endif
#endforeach
This correctly generates the table and the modal:
Modal
The URL for the
Why the Form action dashboard#update does not call?
Because update is actually a PUT call and since form can't do a proper PUT call towards Laravel Controller you need to do form method spoofing and use the code below:
<form class="app-form" id="modal-form" action="{{ route('dashboard', $equipment->id) }}" method="POST">
{{ method_field('PUT') }}
{{ csrf_field() }}
...
add a different rout:
Route::POST('/dashboard/update/{id}', 'DashboardController#update');
Controller:
public function update(Request $request, $id) {
$the_id = $id; //this is the id.
dd($id); //to check your id value.
}
and also try to dd() your variables/ outputs for testing . . .
HTML form
{!! Form::open(['route' => 'events.store','id'=>'form-create-event','name' => 'form-create-event','files'=>true]) !!}
<div class="card">
<div class="card-body card-padding">
<div class="row">
<div id="step1" class="col-sm-4">
<!-- <h3 class="c-gray m-b-15">principales information</h3> -->
<div class="round round-lg blue">
<span>1</span>
</div>
<div class="form-group fg-float">
<div class="fg-line">
<p class="f-200 m-b-5 c-gray">Type d'évènement</p>
<select id="type_event" name="type_event" class="tag-select" data-placeholder="">
#foreach($types_events as $value)
<option value="{!! $value->id !!}">
{{$value->name}}
</option>
#endforeach
</select>
</div>
</div>
<div class="form-group fg-float">
<div class="fg-line">
<input type="text" class="input-sm form-control fg-input" data-rule-minlength='2' required="false" id="event_name" name="event_name">
</div>
<label class="fg-label">Nom de l'évènement</label>
</div>
<!-- <div class="form-group fg-float">
<div class="fg-line">
<input type="text" class="input-sm form-control fg-input input-mask" required="true" data-mask="0000-00-00" name="event_begin_date" id="event_begin_date">
</div>
<label class="fg-label">Date début (expl 2016-01-30)</label>
</div> -->
<div class="input-group form-group">
<span class="input-group-addon"><i class="md md-event"></i></span>
<div class="dtp-container dropdown fg-line">
<input type='text' name="event_begin_date" id="event_begin_date" class="form-control date-picker" data-toggle="dropdown" placeholder="Date début">
</div>
</div>
<!-- <div class="form-group fg-float">
<div class="fg-line">
<input type="text" class="input-sm form-control fg-input input-mask" required="false" data-mask="0000-00-00" id="event_end_date" name="event_end_date">
</div>
<label class="fg-label">Date fin (expl 2016-01-31)</label>
</div> -->
<div class="input-group form-group">
<span class="input-group-addon"><i class="md md-event"></i></span>
<div class="dtp-container dropdown fg-line">
<input type='text' id="event_end_date" name="event_end_date" class="form-control date-picker" data-toggle="dropdown" placeholder="Date fin">
</div>
</div>
<div class='form-group fg-float'>
<div class="fileinput fileinput-new" data-provides="fileinput">
<span class="btn btn-primary btn-file m-r-10">
<span class="fileinput-new">Ajouter un document</span>
<span class="fileinput-exists">Modifier</span>
<input type="file" id="event_document" name="event_document">
</span>
<span class="fileinput-filename"></span>
×
</div>
</div>
<!-- <div id="event_document_tag_name" class="form-group">
<input type="text" placeholder="Tag" id="event_document_tag" name="event_document_tag" class="form-control">
</div> -->
<div class="form-group fg-float">
<div class="fg-line">
<textarea name="event_description" id="event_description" required="false" class="form-control">
</textarea>
</div>
<label class="fg-label">Description</label>
</div>
<div class="form-group fg-float">
<div class="fg-line">
<textarea id="event_info_pr" name="event_info_pr" required="false" class="form-control">
</textarea>
</div>
<label class="fg-label">Informations pratiques</label>
</div>
<div class="form-group fg-float">
<div class="fg-line">
<textarea name="event_adress" required="false" id="event_adress" class="form-control">
</textarea>
</div>
<label class="fg-label">Adresse</label>
</div>
</div>
<div id="step2" class="col-sm-4">
<!-- <h3 class="c-gray m-b-15">informations</h3> -->
<div class="round round-lg blue">
<span>2</span>
</div>
<div class="form-group fg-float">
<div class="fg-line">
<p class="f-200 m-b-5 c-gray">Invités
<a data-toggle="modal" href="#modalDefaultUploadUsers" class="btn btn-success btn-xs waves-effect pull-right">
<i class="md md-file-upload"></i>
</a>
<a style="margin-right: 10px;" data-toggle="modal" href="#modalDefaultAddUser" class="btn btn-success btn-xs waves-effect pull-right">
<i class="md md-add"></i>
</a>
</p>
<select multiple id="event_publics" name="event_publics[]" class="tag-select" data-placeholder="">
#foreach($users as $value)
<option value="{!! $value->id !!}">
{{$value->firstname}} {{$value->lastname}}
</option>
#endforeach
</select>
</div>
</div>
<div class="form-group fg-float">
<div class="fg-line">
<p class="f-200 m-b-5 c-gray">Intervenants
</p>
<select id="event_speakers" name="speakers[]" class="tag-select" multiple data-placeholder="">
#foreach($users as $value)
<option value="{!! $value->id !!}">
{{$value->firstname}} {{$value->lastname}}
</option>
#endforeach
</select>
</div>
</div>
<!-- Groupe et participants -->
<div class="form-group fg-float">
<div class="fg-line">
<p class="f-200 m-b-5 c-gray">Groupes et participants</p>
<!-- <select id="event_gp_participants" name="gps_participants[]" class="demo" multiple="multiple">
#foreach($groups as $group)
#if($group->id !== 1 && $group->id !== 2)
<optgroup value="{{$group->id}}" label="{{$group->name}} ">
#foreach($users as $value)
<option value="group[{{$group->id}}][{{$value->id}}]" >
{{$value->firstname}} {{$value->lastname}}
</option>
#endforeach
</optgroup>
#endif
#endforeach
</select> -->
<select id="event_gp_participants" data-live-search="true" name="gps_participants[]" multiple class="selectpicker">
#foreach($groups as $group) #if($group->id !== 1 && $group->id !== 2)
<optgroup value="{{$group->id}}" label="{{$group->name}} ">
#foreach($users as $value)
<option value="group[{{$group->id}}][{{$value->id}}]">
{{$value->firstname}} {{$value->lastname}}
</option>
#endforeach
</optgroup>
#endif #endforeach
</select>
</div>
</div>
</div>
<div id="step3" class="col-sm-4">
<!-- <h3 class="c-gray m-b-15">informations</h3> -->
<div class="round round-lg blue">
<span>3</span>
</div>
<div class="table-responsive">
<table id="data-table-basic" class="table table-striped table-vmiddle">
<thead>
<tr>
<th colspan="3">
<a class="pull-right" data-toggle="modal" href="#modalWider">
Ajouter séance
</a>
</th>
</tr>
</thead>
<tbody>
<tr></tr>
</tbody>
</table>
</div>
</div>
</div>
<button type="submit" class="btn btn-info"> Enregistrer
</button>
{!! link_to_route('events.index', 'Annuler', [], ['class' => 'btn btn-link']) !!}
</div>
</div>
{!! Form::close() !!}
JS code
var form = document.forms.namedItem("form-create-event");
console.log(form);
form.addEventListener('submit', function(ev) {
oData = new FormData(form);
oData.append("seances", seance);
console.log(oData);
var oReq = new XMLHttpRequest();
oReq.open("POST", form.action, true);
oReq.onload = function(oEvent) {
if (oReq.status == 200) {
console.log('success');
} else {
console.log('failed');
}
};
oReq.send(oData);
ev.preventDefault();
}, false);
PHP code
public function store(Request $request)
{
return response()->json( $request->all());
}
The Problem : dd($request->event_document) returns empty object
header request
Server response
Most probably you are trying to upload files bigger than in size allowed by your php.ini. so set the value of upload_max_filesize and post_max_size in your php.ini :
; Maximum allowed size for uploaded files.
upload_max_filesize = 10M or whatever size you need
; Must be greater than or equal to upload_max_filesize
post_max_size = 10M