I am using Livewire and Slect2 in my project
and I am code to select 2 javascript also but select 2 value is not passed to the database here is my code
My Blade File
<div class="col-12 col-lg-12 col-sm-12">
<div wire:ignore>
<div class="form-group">
<label for="exampleInputRounded0">Section Name</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-globe-asia text-primary"></i></span>
</div>
<select class="form-control rounded-0 " wire:model="cr_classes_id" id="cr_classes_id" style="width: 100%;" tabindex="-1" aria-hidden="true">
#foreach ($classes as $class)
<option value="{{$class->id}}">{{$class->classes_name}}</option>
#endforeach
</select>
</div>
#error('cr_classes_sec_id') <span class="text-danger error">{{ $message }}</span>#enderror
</div>
</div>
</div>
Here is My JS
#push('js')
<script type="text/javascript">
$(document).ready(function () {
$('#cr_classes_id').select2();
$('#cr_classes_id').on('change', function (e) {
var data = $('#cr_classes_id').select2("val");
#this.set('cr_classes_id', data);
});
});
</script>
#endpush
Consol Error
Uncaught TypeError: Cannot read property '$wire' of undefined
at Livewire.value (index.js:31)
at HTMLSelectElement.<anonymous> (ClassRooms:844)
at HTMLSelectElement.dispatch (jquery.min.js:2)
at HTMLSelectElement.v.handle (jquery.min.js:2)
at Object.trigger (jquery.min.js:2)
at HTMLSelectElement.<anonymous> (jquery.min.js:2)
at Function.each (jquery.min.js:2)
at k.fn.init.each (jquery.min.js:2)
at k.fn.init.trigger (jquery.min.js:2)
at n.select (select2.min.js:2)
without wire:ignore Working find and data send to the database
Try this
<div class="col-12 col-lg-12 col-sm-12">
<div wire:ignore.self>
<div class="form-group">
<label for="exampleInputRounded0">Section Name</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-globe-asia text-primary"></i></span>
</div>
<select class="form-control rounded-0 " wire:change="$emit('classChanged', $event.target.value)" style="width: 100%;" tabindex="-1" aria-hidden="true">
#foreach ($classes as $class)
<option value="{{$class->id}}" {{ $cr_classes_id ? 'selected' : ''}} >{{$class->classes_name}}</option>
#endforeach
</select>
</div>
#error('cr_classes_sec_id') <span class="text-danger error">{{ $message }}</span>#enderror
</div>
</div>
</div>
and in component
public $cr_classes_id = '';
public $listeners = [
'classChanged'
];
......
public function classChanged($value)
{
$this->cr_classes_id = $value;
}
try to add ":key="cr_classes_id_key" in your blade file
<div class="col-12 col-lg-12 col-sm-12">
<div wire:ignore :key="cr_classes_id_key">
<div class="form-group">
<label for="exampleInputRounded0">Section Name</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-globe-asia text-primary"></i></span>
</div>
<select class="form-control rounded-0 " wire:model="cr_classes_id" id="cr_classes_id" style="width: 100%;" tabindex="-1" aria-hidden="true">
#foreach ($classes as $class)
<option value="{{$class->id}}">{{$class->classes_name}}</option>
#endforeach
</select>
</div>
#error('cr_classes_sec_id') <span class="text-danger error">{{ $message }}</span>#enderror
</div>
</div>
Related
I am insert data product with images in dashboard, when I try to order the product I have error 404 not found and the URL showing value database in table like http://127.0.0.1:8000/shops/order/[%7B%22id%22:2,%22category_id%22:1,%22name_product%22:%22asdasd%22,%22harga%22:123123123,%22image%22:%22product-images//HapOzHmJPim1kIfmIeCM21xesCnIbR5Z7lpzcO8M.jpg%22,%22published_at%22:null,%22created_at%22:%222022-05-23T16:25:00.000000Z%22,%22updated_at%22:%222022-05-23T16:25:10.000000Z%22,%22kategori%22:%7B%22id%22:1,%22name_category%22:%22Top%22,%22created_at%22:%222022-05-23T16:22:40.000000Z%22,%22updated_at%22:%222022-05-23T16:22:40.000000Z%22%7D%7D].
But when I am insert data product without images in dashboard, and then I try to order the product is successful.
This is my route
Route::post('/shops/order/{shop:id}', [OrderController::class, 'store']);
This is OrderController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Order;
use App\Models\User;
use App\Models\Shop;
class OrderController extends Controller
{
public function store(Request $request)
{
$createOrder = $request->validate([
'user_id' => 'required',
'name_product_id' => 'required',
'size' => 'required',
'no' => 'required',
'address' => 'required'
]);
Order::create($createOrder);
return redirect('shops/order/{shop:id}')->with('success', 'Order is successfully!');
}
}
This is my views
#extends('layouts.main')
#section('container')
<div class="container">
<div class="row mt-5">
#foreach ($shops as $shop)
<div class="card mb-3">
<div class="row g-0">
<div class="col-md-4">
<img src="{{ asset('storage/' . $shop->image) }}" alt="{{ $shop->name_product }}" class="img-fluid rounded-start" style="max-height: 400px; overflow:hidden">
</div>
<div class="col-md-8">
<div class="card-body">
<h5 class="card-title">{{ $shop->name_product }}</h5>
<p>Jenis {{ $shop->category->name_category }}</p>
<p class="card-text fw-bold">Rp.{{ $shop->price }}</p>
</div>
</div>
</div>
</div>
#endforeach
</div>
<div class="row mt-5">
<div class="col align-self-center">
#if (session()->has('success'))
<div class="alert alert-success text-center" role="alert">
{{ session('success') }}
</div>
#endif
</div>
</div>
<form method="POST" action="/shops/order/{{ $shops }}" class="row g-2" enctype="multipart/form-data">
#csrf
<h3 class="text-center mt-2">Detail Delivery</h3>
<div class="col-md-6">
<div class="mb-3">
<select class="form-select" name="user_id" hidden>
#foreach ($users as $name)
<option value="{{ $name->id }}">{{ $name->id }}</option>
#endforeach
</select>
</div>
<div class="mb-3">
<select class="form-select" name="name_produk_id" hidden>
#foreach ($shops as $shops_id)
<option value="{{ $shops_id->id }}">{{ $shops_id->id }}</option>
#endforeach
</select>
</div>
<div class="mb-3">
<label for="address" class="form-label">Address</label>
<textarea class="form-control" #error('address') is-invalid #enderror id="address" name="address" required>
</textarea>
</div>
</div>
<div class="col-md-4">
<label for="size" class="form-label mt-3">Select size :</label>
<select class="form-select" name="size">
<option selected>S</option>
<option value="M">M</option>
<option value="L">L</option>
<option value="XL">XL</option>
</select>
<div class="mt-3">
<label for="no" class="form-label">Nomor Whatsapp</label>
<input class="form-control" #error('no') is-invalid #enderror id="no" name="no" required autofocus">
</div>
<button type="submit" class="btn btn-primary mt-5">Buy Now</button>
</div>
</form>
</div>
#endsection
I am trying to import data into MySQL from an Excel file. My table has 2 foreign keys project_id and site_id when importing I am selecting these 2 fields from dropdowns in my View. Is there a way I can map these 2 fields to my import collection? Mind you, the 2 fields do not exist in the import file (for integrity reasons) but they do exist in the table.
Collection
namespace App\Imports;
use App\Proposal;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
class ProposalsImport implements ToModel, WithHeadingRow
{
public function model(array $row)
{
return new Proposal([
'building' => $row['building'],
'floor' => $row['floor'],
'area' => $row['area'],
'room' => $row['room'],
'luminaire' => $row['luminaire'],
'actual_qty' => $row['actual_qty'],
'installed_qty' => $row['installed_qty'],
]);
}
}
Controller
public function import()
{
Excel::import(new ProposalsImport, 'proposals.xlsx');
}
View
#extends('projectmanagement/proposals.base')
#section('action-content')
<!-- Main content -->
<section class="content">
<div class="container">
<div class="box">
<div class="box-header">
</div>
<!-- /.box-header -->
<div class="box-body" data-widget="box-refresh">
#if (session('status'))
<div style="padding-top: 0px;padding-bottom: 0px;"
class="alert alert_cust alert-success alert-dismissable fade in">{{ session('status') }}×</div>
#endif
</div>
<div class="row">
<div class="col-lg-12">
<form class="form-horizontal" role="form" method="POST" enctype="multipart/form-data" action="{{ route('proposals.store') }}">
{{ csrf_field() }}
<div class="row">
<div class="col-md-12">
<div class="form-group{{ $errors->has('project_id') ? ' has-error' : '' }}">
<label for="project_id" class="col-md-4 control-label">Project Name</label>
<div class="col-md-6">
<select id="project_id" class="form-control select2" style="width: 100%;"
name="project_id">
<option value="0" disabled selected>Select Project</option>
#foreach ($projects as $project)
<option value="{{$project->id}}">{{ $project->project_name }}</option>
#endforeach
</select>
#if ($errors->has('project_id'))
<span class="help-block">
<strong>{{ $errors->first('project_id') }}</strong>
</span>
#endif
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<br/>
<div class="form-group{{ $errors->has('site_id') ? ' has-error' : '' }}">
<label for="site_id" class="col-md-4 control-label">Site Name</label>
<div class="col-md-6">
<select id="site_id" class="form-control select2" style="width: 100%;"
name="site_id">
<option value="0" disabled selected>Select Site</option>
#foreach ($sites as $site)
<option value="{{$site->id}}">{{ $site->site_name }}</option>
#endforeach
</select>
#if ($errors->has('site_id'))
<span class="help-block">
<strong>{{ $errors->first('site_id') }}</strong>
</span>
#endif
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<br/>
<div class="form-group{{ $errors->has('proposal_file') ? ' has-error' : '' }}">
<label for="proposal_file" class="col-md-4 control-label">Proposal File</label>
<div class="col-md-6">
<input id="proposal_file" type="file" class="form-control" name="proposal_file" required autofocus>
#if ($errors->has('proposal_file'))
<span class="help-block">
<strong>{{ $errors->first('proposal_file') }}</strong>
</span>
#endif
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<br/>
<div class="form-group">
<div class="col-md-4">
</div>
<div class="col-md-6">
<button type="submit" class="btn col-sm-3 col-xs-5 btn-primary">Upload Proposal</button>
</div>
</div>
<br/>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
#push('custom_scripts')
<script>
</script>
#endpush
#endsection
Override import controller's construct method, sending all the parameters you need, like this:
class ProposalsImport implements ToModel, WithHeadingRow
{
protected $project_id;
protected $site_id;
public function __construct($project_id, $site_id)
{
$this->project_id = $project_id;
$this->site_id = $site_id;
}
public function model(array $row)
{
return new Proposal([
'building' => $row['building'],
'project_id' => $this->project_id,
'site_id' => $this->site_id
]);
}
}
And then, call it from your Controller like this:
public function import(Request $request)
{
Excel::import(new ProposalsImport($request->project_id, $request->site_id), 'proposals.xlsx');
}
I'm trying to upload a file with Laravel but it does not work
I will send the field with the meta name view
<div class="panel-body">
<div class="tab-content">
<div class="tab-pane fade in active" id="tab1success">
<form method="post" name="type" action="songs">
{{ csrf_field() }}
<div class="form-group">
<div class="row">
<label class="col-md-3 control-label" for="Name">نام موزیک</label>
<div class="col-md-7">
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-music">
</i>
</div>
<input id="Name" name="title" type="text"
placeholder="نام موزیک" class="form-control input-md">
</div>
</div>
</div>
<br>
<div class="row">
<label class="col-md-3 control-label" for="Name (Full name)">دسته
بندی</label>
<div class="col-md-7">
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-list">
</i>
</div>
<select id="Name" name="category" type="دسته بندی"
placeholder="دسته بندی" class="form-control input-md">
<option>fun</option>
<option>love</option>
<option>birth</option>
<option>wedding</option>
</select>
</div>
</div>
</div>
<br>
<div class="row">
<label class="col-md-3 control-label" for="Name (Full name)">توضیحات</label>
<div class="col-md-7">
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-file-text-o">
</i>
</div>
<textarea id="Name" name="text" placeholder="توضیحات"
class="form-control input-md"></textarea>
</div>
</div>
</div>
<br>
<div class="row">
<label class="col-md-3 control-label" for="Name (Full name)">انتخاب
فایل</label>
<div class="col-md-7">
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-folder-o">
</i>
</div>
<input id="meta" name="meta" type="file" placeholder="انتخاب فایل"
class="form-control input-md">
</div>
</div>
</div>
<br>
<div class="row" style="text-align: center">
<div class="col-md-10 " style="text-align: center">
<button id="Name" name="submit" type="submit" placeholder="انتخاب فایل"
class="form-control input-md" style="text-align: center">اضافه
</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
Controller
public function create(Request $req, $type) {
$this->authorize('is_admin');
$req->file('meta')->store('app');
// $path = Storage::putFile('app', $req->file('meta'))
}
error
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Call to a member function store() on null
Here is an image of the error
Does anybody know what i should do about this?
Add enctype="multipart/form-data" to your <form> tag in your blade:
<form method="post" name="type" action="songs" enctype="multipart/form-data">
Based on your blade file you can see that the file meta being uploaded is not required, so in your controller, you need to check if the file was sent before calling the store method on it. Check this:
public function create(Request $req, $type) {
$this->authorize('is_admin');
$file = $req->file('meta') ? $req->file('meta')->store('app') : null;
}
I want to insert to DB with array input. but have an error. Please help me
this is my code:
in view
Số công văn
<div class="form-group">
<label for="exampleInputpwd1">Người phê duyệt</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-thumbs-o-up"></i></div>
<select class="form-control" name="txtleader[]">
<?php
$list_ld = DB::table('leaders')->select('id','Name')->get();
?>
#foreach($list_ld as $item_ld)
<option value="{!! $item_ld->id !!}">{!! $item_ld->Name !!}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group">
<label for="exampleInputEmail1">Lí do xin vé</label>
<div class="input-group">
<div class="input-group-addon"><i class="icon-question"></i></i></div>
<select class="form-control" name="txtlido[]">
<?php
$list_rs = DB::table('reasons')->select('id','Name')->get();
?>
#foreach($list_rs as $item_rs)
<option value="{!! $item_rs->id !!}">{!! $item_rs->Name !!}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group">
<label for="exampleInputpwd2">Công ty</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-bank"></i></div>
<select class="form-control" name="txtCom[]">
<?php
$list_c = DB::table('companies')->select('id','NameCOM')->get();
?>
#foreach($list_c as $item_c)
<option value="{!! $item_c->id !!}">{!! $item_c->NameCOM !!}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group">
<label for="exampleInputpwd2">Phòng</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-building-o"></i></div>
<select class="form-control" name="txtRoom[]">
<?php
$list_r = DB::table('rooms')->select('id','NameRO')->get();
?>
#foreach($list_r as $item_r)
<option value="{!! $item_r->id !!}">{!! $item_r->NameRO !!}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group">
<label for="exampleInputpwd2">Giao cho</label>
<div class="input-group">
<div class="input-group-addon"><i class="ti-share"></i></div>
<input type="text" class="form-control" id="exampleInputuname" placeholder="Chi nhánh/Đại diện nhận nhiệm vụ" name="txtReceiver[]">
</div>
</div>
<div class="form-group">
<div class="checkbox checkbox-success"></div>
</div>
<div class="text-right"></div>
</div>
<div class="col-md-6">
<div class="form-group nguoixin">
<label for="exampleInputuname">Người xin</label>
<div class="input-group">
<div class="input-group-addon"><i class="icon-user"></i></div>
<input type="text" class="form-control" id="exampleInputuname" placeholder="Người xin" name="txtnguoixin[]">
<input type="text" class="form-control" id="exampleInputuname" placeholder="Người xin" name="txtnguoixin[]">
<div class="input-group-addon"><button class="add-more-nx"><i class="fa fa-plus"></i></button></div>
</div>
</div>
<div class="form-group">
<label for="exampleInputuname">Mối quan hệ</label>
<div class="input-group">
<div class="input-group-addon"><i class="ti-exchange-vertical"></i></div>
<select class="form-control" name="txtRelation[]">
<?php
$list_rl = DB::table('relationship')->select('id','Name')->get();
?>
#foreach($list_rl as $item_rl)
<option value="{!! $item_rl->id !!}">{!! $item_rl->Name !!}</option>
#endforeach
</select>
<div class="input-group-addon"><button><i class="fa fa-plus"></i></button></div>
</div>
</div>
<div class="form-group">
<label for="exampleInputEmail1">Người đi</label>
<div class="input-group">
<div class="input-group-addon"><i class="icon-people"></i></div>
<textarea class="form-control" rows="5" name="txtGuest[]"></textarea>
<div class="input-group-addon"><button><i class="fa fa-plus"></i></button></div>
</div>
</div>
<div class="form-group">
<label for="exampleInputpwd1">chặng bay</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-fighter-jet"></i></div>
<select class="form-control" name="txtFlies[]">
<?php
$list_cb = DB::table('return')->select('id','CodeFN')->get();
?>
#foreach($list_cb as $item_cb)
<option value="{!! $item_cb->id !!}">{!! $item_cb->CodeFN !!}</option>
#endforeach
</select>
<div class="input-group-addon"><button><i class="fa fa-plus"></i></button></div>
</div>
</div>
<div class="form-group">
<label for="exampleInputpwd2">mức giảm</label>
<div class="input-group">
<div class="input-group-addon"><i class="ti-package"></i></div>
<select class="form-control" name="txtDiscount[]">
<?php
$list_dc = DB::table('discounts')->select('id','CodeDist')->get();
?>
#foreach($list_dc as $item_dc)
<option value="{!! $item_dc->id !!}">{!! $item_dc->CodeDist !!}</option>
#endforeach
</select>
<div class="input-group-addon"><button><i class="fa fa-plus"></i></button></div>
</div>
</div>
<div class="form-group">
<div class="checkbox checkbox-success"> </div>
</div>
<div class="text-right">
<button type="submit" class="btn btn-success waves-effect waves-light m-r-10">Thêm mới</button>
</div>
</form>
my controller
$input = Input::all();
$count = count($input['txtnguoixin']);
$ticketin = array();
for($i=1; $i<$count; $i++){
if($input['txtnguoixin'][$i]){
array_push($ticketin, array(
'NoCV' => $input['txtSCV'][$i],
'nguoixin' => $input['txtnguoixin'][$i],
'Com_id' => $input['txtCom'][$i],
'Room_id' => $input['txtRoom'][$i],
'Reason_id' => $input['txtlido'][$i],
'Nguoidi' => $input['txtGuest'][$i],
'Relation_id' => $input['txtRelation'][$i],
'return_id' => $input['txtFlies'][$i],
'discount_id' => $input['txtDiscount'][$i],
'leader_id' => $input['txtleader'][$i],
'nguoinhap' => 'muoi',
'assignto' => $input['txtReceiver'][$i],
'tinhtrang' => 1
));
}
}
echo "<pre>";
print_r($ticketin);
echo "</pre>";
But it has erro undefined offset 1.
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