Laravel fullcalendar- How to display the event specifically on the current user? - php

I had developed a system that use maddhatter/laravel-fullcalendar.It works and i had no problem to display the calendar with the events.However, there is the problem that the calendar show all events include from different users.Can someone help me to solve this?
Controller
//show the events in the calendar
$events = Schedule::get();
$events->user()->id;
$event_list = [];
foreach ($events as $key => $event) {
$event_list[] = Calendar::event(
$event->event_name,
false,
new \DateTime($event->start_date),
new \DateTime($event->end_date),
null,
// Add color and link on event
[
'color' => '#05B06C',
//'url' => 'http://full-calendar.io',
]);
}
//Display Fullcalendar
$calendar_details = Calendar::addEvents($event_list)
->setOptions([ //set fullcalendar options
'firstDay'=> 1,
'editable'=> true,
'navLinks'=> true,
'selectable' => true,
'durationeditable' => true,
]);
return view('front.teacher.schedule.index', compact('calendar_details','events') );
}
Model
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class Schedule extends Model
{
protected $fillable=[
'event_name','start_date','end_date'
];
}
View
{!! Form::open(array('route' =>'schedule:addEvents','method'=>'POST','files'=>'true'))!!}
<div class ="row">
<div class="col-xs-12 col-sm-12 col-md-12">
#if(Session::has('success'))
<div class="alert alert-success">{{Session::get('success')}}</div>
#elseif (Session::has('warning'))
<div class="alert alert-danger">{{Session::get('warning')}}</div>
#endif
</div>
<div class="col-xs-4 col-sm-4 col-md-4">
<div class="form-group">
{!! Form::label('event_name','Name:') !!}
<div class="">
{!! Form::text('event_name',null,['class'=>'form-control'])!!}
{!! $errors->first('event_name','<p class="alert alert-danger">:message</p>') !!}
</div>
</div>
</div>
<div class="col-xs-3 col-sm-3 col-sm-3">
<div class="form-group">
{!! Form::label('start_date','Start Date:')!!}
<div class="">
{!! Form::input('datetime-local','start_date',\Carbon\Carbon::now(),['class' => 'form-control']) !!}
{!! $errors->first('start_date', '<p class="alert alert-danger">:message</p>') !!}
</div>
</div>
</div>
<div class="col-xs-3 col-sm-3 col-md-3">
<div class="form-group">
{!!Form::label('end_date','End Date:')!!}
<div class="">
{!! Form::input('datetime-local','end_date',null, ['class' => 'form-control']) !!}
{!! $errors->first('end_date', '<p class="alert alert-danger">:message</p>') !!}
</div>
</div>
</div>
<div class="col-xs-1 col-sm-1 cold-md-1 text-center"> <br/>
{!! Form::submit('Add Event',['class'=>'btn btn-primary']) !!}
</div>
</div>
{!!Form::close() !!}
</div>
</div>
<div class="panel panel-primary">
<div class="panel-heading">My Event Details</div>
<div class="panel-body">
{!! $calendar_details->calendar() !!}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
#section('script')
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.js"></script>
{!! $calendar_details->script() !!}
Schedule Table
Table

Related

Adding two different controllers to a single blade view in laravel which contains two deifferent forms

In my laravel application, I have a view to edit my non-admin users (participants) (via admin dashboard).
In this application, each user can add a pet too.
Once an admin goes to a certain participant's profile admin should be able to edit the participant and also the pet info as well if needed.
For that, I have to use two forms, one to update the user and another to update the pet. But both the forms are in a single view.
I've already created the participant controller (ParticipantController) and tested all the methods are working fine.
For the pets too I created a different model and a controller(PetsController).
But now I'm struggling to connect my pets controller to the participant edit blade.
following is the routing for the relevant scenario in my web.php
Route::group(['middleware' => ['auth']], function() {
Route::resource('/admins/roles','Admin\RoleController');
Route::resource('/admins/users','Admin\UserController');
Route::resource('/admins/participants','Admin\ParticipantController');
});
I've already created the participant's edit form which works properly and looking for some help to adding the petscontroller to the same blade.
following is my participants edit blade
#extends('layouts.admin')
#section('content')
<div class="row">
<div class="col-md-9">
<h2 class="view-title">{{ __('Edit User') }}</h2>
</div>
<div class="col-md-3">
<div class="text-left">
<!-- <a class="btn btn-primary btn-admin" href="{{ route('users.index') }}"> {{ __('Back') }}</a> -->
</div>
</div>
</div>
#if ($message = Session::get('success'))
<div class="alert alert-success">
<a class="close" onclick="jQuery('.alert').hide()">×</a>
<p>{{ $message }}</p>
</div>
#endif
<div class="row">
<div class="col-md-12" mt-5>
#if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
</div>
</div>
{!! Form::model($user, ['method' => 'PATCH','enctype'=>'multipart/form-data','route' => ['participants.update', $user->id]]) !!}
<div class="row">
<div class="col-md-3 mt-5">
<!-- #if($user->image_id != 'default-avatar.png')
<button type="submit" name="resetphoto" class="btn btn-danger px-3 mr-5 pull-right"><i class="fa fa-trash" aria-hidden="true"></i>
</button>
#endif
-->
#if(empty($user->image_id))
<center> <img src="/propics/default-avatar.png" alt="Profile Pic" id="profile_pic_display_settings" class="mb-3"></center>
</p>
#else
<center> <img src="/propics/{{$user->image_id}}" alt="Profile Pic" id="profile_pic_display_settings" class="mb-3"></center>
#endif
<center><label for="propic" class="btn btn-default subscribe"><i class="fas fa-camera"></i></label></center>
<input id="propic" type="file" name="image_id" class="form-control">
<label id="file_name"></label>
#error('propic')
<span class="help-block" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
<div class="col-md-9 mt-5">
<div class="form-group row">
<div class="col-md-6">
{!! Form::text('first_name', null, array('placeholder' => 'First Name','class' => 'form-control txt_txt')) !!}
{!! $errors->first('first_name', '<span class="help-block" role="alert">:message</span>') !!}
</div>
<div class="col-md-6">
{!! Form::text('last_name', null, array('placeholder' => 'Last Name','class' => 'form-control txt_txt')) !!}
{!! $errors->first('last_name', '<span class="help-block" role="alert">:message</span>') !!}
</div>
</div>
<div class="form-group row">
<div class="col-md-6 ">
{!! Form::text('email', null, array('placeholder' => 'Email','class' => 'form-control txt_txt')) !!}
{!! $errors->first('email', '<span class="help-block" role="alert">:message</span>') !!}
</div>
<div class="col-md-6 ">
{!! Form::password('password', array('placeholder' => 'Password','class' => 'form-control txt_txt')) !!}
{!! $errors->first('password', '<span class="help-block" role="alert">:message</span>') !!}
</div>
</div>
<div class="form-group row">
<div class="col-md-6 ">
{!! Form::password('confirm-password', array('placeholder' => 'Confirm Password','class' => 'form-control txt_txt')) !!}
</div>
<div class="col-md-6">
{!! Form::select('roles[]', $roles,$userRole, array('class' => 'form-control','multiple')) !!}
{!! $errors->first('roles', '<span class="help-block" role="alert">:message</span>') !!}
{!! Form::text('role_id','null', array('class' => 'form-control txt_none')) !!}
{!! Form::text('gender','null', array('class' => 'form-control txt_none')) !!}
</div>
</div>
<div class="col-md-12 text-right px-0 ">
<a class="btn btn-primary btn-admin-form-cancel mt-5" href="{{ route('participants.index') }}"> {{ __('Cancel') }}</a>
<button type="submit" class="btn btn-primary btn-admin-form-save mt-5">{{ __('Save') }}</button>
</div>
</div>
</div>
{!! Form::close() !!}
<div class="row">
<hr class="black_line">
</div>
{!! Form::model($user, ['method' => 'PATCH','enctype'=>'multipart/form-data','route' => ['participants.update', $user->id]]) !!}
<div class="row">
<div class="col-md-3 mt-5">
<!-- #if($user->image_id != 'default-avatar.png')
<button type="submit" name="resetphoto" class="btn btn-danger px-3 mr-5 pull-right"><i class="fa fa-trash" aria-hidden="true"></i>
</button>
#endif
-->
#if(empty($user->image_id))
<center> <img src="/propics/default-avatar.png" alt="Profile Pic" id="profile_pic_display_settings" class="mb-3"></center>
</p>
#else
<center> <img src="/propics/{{$user->image_id}}" alt="Profile Pic" id="profile_pic_display_settings" class="mb-3"></center>
#endif
<center><label for="propic" class="btn btn-default subscribe"><i class="fas fa-camera"></i></label></center>
<input id="propic" type="file" name="image_id" class="form-control">
<label id="file_name"></label>
#error('propic')
<span class="help-block" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
<div class="col-md-9 mt-5">
<div class="form-group row">
<div class="col-md-6">
{!! Form::text('first_name', null, array('placeholder' => 'Pet Name','class' => 'form-control txt_txt')) !!}
{!! $errors->first('first_name', '<span class="help-block" role="alert">:message</span>') !!}
</div>
<div class="col-md-6">
{!! Form::text('pet_age', null, array('placeholder' => 'Pet Age','class' => 'form-control txt_txt')) !!}
{!! $errors->first('pet_age', '<span class="help-block" role="alert">:message</span>') !!}
</div>
</div>
<div class="col-md-12 text-right px-0 ">
<a class="btn btn-primary btn-admin-form-cancel mt-5" href="{{ route('participants.index') }}"> {{ __('Cancel') }}</a>
<button type="submit" class="btn btn-primary btn-admin-form-save mt-5">{{ __('Save') }}</button>
</div>
</div>
</div>
{!! Form::close() !!}
#endsection

Method Illuminate\Database\Eloquent\Collection::create does not exist

I want to copy values from row from one table (proforms), to row in another table (invoices) using button in view. But getting error: Method Illuminate\Database\Eloquent\Collection::create does not exist.
On line: 'grosstotal' => $proform->grosstotal,
This is my controller method:
public function duplicate(Request $request)
{
$proform = $this->proform->findOrFail($request->duplicate);
$invoice = Invoice::all();
//something like this
$duplicated = $invoice->create([
'invoicenumber' => $proform->proformnumber,
'invoicedate' => $proform->proformdate,
'selldate' => $proform->selldate,
'user_id' => $proform->user_id,
'form_id' => $proform->form_id,
'currency_id' => $proform->currency_id,
'paymentmethod' => $proform->paymentmethod,
'paymentdate' => $proform->paymentdate,
'status' => $proform->status,
'comments' => $proform->comments,
'city' => $proform->city,
'autonumber' => $proform->autonumber,
'automonth' => $proform->automonth,
'autoyear' => $proform->autoyear,
'name' => $proform->name,
'PKWIU' => $proform->PKWIU,
'quantity' => $proform->quantity,
'unit' => $proform->unit,
'netunit' => $proform->netunit,
'nettotal' => $proform->nettotal,
'VATrate' => $proform->VATrate,
'grossunit' => $proform->grossunit,
'grosstotal' => $proform->grosstotal,
]);
return redirect()->route('invoices.show', ['invoice' => $duplicated]);
}
This is my view with button for duplicate:
#extends('layouts.app')
#section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Szczegóły abonamentu</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('proforms.index') }}"> Wstecz</a>
</div>
</div>
</div>
<div class="col-md-4">
<form action="{{ route('proforms.duplicate') }}" method="POST">
#csrf
<div class="input-group">
<input type="text" value="1" name="duplicate" class="form-control" readonly>
<span class="input-group-prepend">
<button type="submit" class="btn btn-primary">Wystaw fakturę</button>
</span>
</div>
</form>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Data wystawienia:</strong>
{{ $proform->proformdate }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Kontrahent:</strong>
{{ $proform->user_id }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Data sprzedaży:</strong>
{{ $proform->selldate }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Termin płatności:</strong>
{{ $proform->paymentdate }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Forma płatności:</strong>
{{ $proform->paymentmethod }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Miejsce wystawienia:</strong>
{{ $proform->city }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Status:</strong>
{{ $proform->status }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Uwagi:</strong>
{{ $proform->comments }}
</div>
</div>
<div class="pull-left" style="margin: 15px;">
<h3>Pozycje proformy</h3>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Nazwa towaru lub usługi:</strong>
{{ $proform->name }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>PKWiU:</strong>
{{ $proform->PKWIU }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Ilość:</strong>
{{ $proform->quantity }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Jednostka:</strong>
{{ $proform->unit }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Cena netto jednostki:</strong>
{{ $proform->netunit }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Netto razem:</strong>
{{ $proform->nettotal }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Stawka VAT:</strong>
{{ $proform->VATrate }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Brutto jednostka:</strong>
{{ $proform->grossunit }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Brutto razem:</strong>
{{ $proform->grosstotal }}
</div>
</div>
</div>
#endsection
This is my routes
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function(){
return view('welcome');
});
Route::get('home');
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
Route::group(['middleware' => ['auth']], function () {
Route::get('/search', 'UserController#search');
Route::get('/search2', 'ProductController#search2');
Route::get('/search3', 'ProformController#search3');
Route::get('/search4', 'InvoiceController#search4');
Route::post('/duplicate', 'ProformController#duplicate')->name('proforms.duplicate');
Route::get('data', 'UserController#index');
Route::get('posts', 'PostController#index');
Route::get('/prodview', 'TestController#prodfunct');
Route::resource('roles', 'RoleController');
Route::resource('users', 'UserController');
Route::resource('permissions', 'PermissionController');
Route::resource('products', 'ProductController');
Route::resource('invoices', 'InvoiceController');
Route::resource('category', 'CategoryController');
Route::resource('invoices', 'InvoiceController');
Route::resource('proforms', 'ProformController');
});
Duplicate is for it.
In your code you have
// all() gets you the collection of the Invoice Model instances of all the entries of invoice in the database.
$invoice = Invoice::all();
$duplicated = $invoice->create([..
Where
$invoice is a collection of Invoice Model instances. You can't apply create method on a collection.
You need to create by using the Model that you have for Invoice.
So change the above creation code to
$duplicated = Invoice::create([..

How to add Edit and Delete function in my FullCalendar laravel ph?

I'm doing a project in laravel, where I can show my list of events using fullcalendar. I already created/have a fullcalendar view with events and adding event, but I want to be able to click the date and edit it or delete it.
Sample event fullcalendar
I already search some solutions or guides for this, but I can't work it properly. I tried creating another one from scratch but it doesn't work.
Here are the links that I searched and doing it as my guide.
FullCalendar Events and Scheduling
github driftingruby/042-fullcalendar
This is my codes in my create.blade.php
<div class="container">
<div class="panel panel-primary">
<div class="panel-heading">Event Calendar</div>
<div class="panel-body">
{!! Form::open(array('route' => 'admin/events.create','method'=>'POST','files'=>'true')) !!}
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
#if (Session::has('success'))
<div class="alert alert-success">{{ Session::get('success') }}</div>
#elseif (Session::has('warning'))
<div class="alert alert-danger">{{ Session::get('warning') }}</div>
#endif
</div>
<div class="col-xs-4 col-sm-4 col-md-4">
<div class="form-group">
{!! Form::label('event_name','Event Name:') !!}
<div class="">
{!! Form::text('event_name', null, ['class' => 'form-control']) !!}
<!-- {!! $errors->first('event_name', '<p class="alert alert-danger">:message</p>') !!} -->
</div>
</div>
</div>
<div class="col-xs-3 col-sm-3 col-md-3">
<div class="form-group">
{!! Form::label('start_date','Start Date:') !!}
<div class="">
{!! Form::date('start_date', null, ['class' => 'form-control']) !!}
<!-- {!! $errors->first('start_date', '<p class="alert alert-danger">:message</p>') !!} -->
</div>
</div>
</div>
<div class="col-xs-3 col-sm-3 col-md-3">
<div class="form-group">
{!! Form::label('end_date','End Date:') !!}
<div class="">
{!! Form::date('end_date', null, ['class' => 'form-control']) !!}
<!-- {!! $errors->first('end_date', '<p class="alert alert-danger">:message</p>') !!} -->
</div>
</div>
</div>
<div class="col-xs-1 col-sm-1 col-md-1 text-center"> <br/>
{!! Form::submit('Add Event',['class'=>'btn btn-primary']) !!}
</div>
</div>
{!! Form::close() !!}
</div>
</div>
<div class="panel panel-primary">
<div class="panel-heading">Event Details</div>
<div class="panel-body">
{!! $calendar_details->calendar() !!}
</div>
</div>
</div>
<link rel="stylesheet" href="https://cdjns.cloudfare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.css"/>
<!-- Scripts -->
<script src="http://code.jquery.com/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.js"></script>
{!! $calendar_details->script() !!}
And this is my code for my AdminEventsController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Events;
use App\Barangay;
use Illuminate\Support\Facades\Auth;
use Session;
use Calendar;
class AdminEventsController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index() {
$events = Events::get();
$event_list = [];
foreach ($events as $key => $event) {
$event_list[] = Calendar::event(
$event->event_name,
true,
new \DateTime($event->start_date),
new \DateTime($event->end_date.' +1 day')
);
}
$calendar_details = Calendar::addEvents($event_list);
return view('admin.events.create', compact('calendar_details') );
}
public function addEvent(Request $request)
{
$mybrgyid = Auth::user()->brgyid;
$mybarangay = Barangay::select('brgyname')->where('id', $mybrgyid)->get();
session(['mybarangay' => $mybarangay]);
$this->validate($request,[
'event_name' => 'required',
'start_date' => 'required',
'end_date' => 'required'
]);
//$validator = validator::make($request->all(), [
//'event_name' => 'required',
//'start_date' => 'required',
//'end_date' => 'required'
//]);
//if ($validator->fails()) {
// \session::flash('warning', 'Please enter the valid details');
// return Redirect::to('/admin/events')->withErrors($validator);
//}
$event = new Events;
$event->brgyid = Auth::user()->id;
$event->event_name = $request['event_name'];
$event->start_date = $request['start_date'];
$event->end_date = $request['end_date'];
$event->save();
return redirect('/admin/events')->with('success', 'Event Created');
}
}
Somehow I'm being confuse as to where I would create a modal for editing and deleting an event in my fullcalendar.
Your help is much appreciated.

Laravel form with multiple select didn't send all selected data when submit

I have Laravel form with many multiple select elements which has many data. for ex:
Hotel select (600 option)
Restaurants select (800 option)
SPA select (200 option)
Attractions select (150 option)
Outlets select (500 option)
If I select all options in all inputs, in the controller when checking the
request the (Outlets) item has only 200 option
how to fix this? how to got all data sent from this form?
is there any form data size in Laravel?
This my form code:
<div class="row">
<div class="panel panel-white">
<div class="panel-body">
<div class="col-md-12 col-sm-12">
<div class="form-group">
{{ Form::label('hotels', __('membership::main.hotels')) }}
{{ Form::select('hotels', $hotels, null, array('multiple'=>'multiple','name'=>'hotels[]', 'class' => 'multiselect form-control')) }}
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-white">
<div class="panel-body">
<div class="col-md-12 col-sm-12">
<div class="form-group">
{{ Form::label('outlets', __('membership::main.outlets')) }}
{{ Form::select('outlets', $outlets, null, array('multiple'=>'multiple','name'=>'outlets[]', 'class' => 'multiselect form-control')) }}
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-white">
<div class="panel-body">
<div class="col-md-12 col-sm-12">
<div class="form-group">
{{ Form::label('airports', 'Airport & Lounges') }}
{{ Form::select('airports', $airports, null, array('multiple'=>'multiple','name'=>'airports[]', 'class' => 'multiselect form-control')) }}
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-white">
<div class="panel-body">
<div class="col-md-12 col-sm-12">
<div class="form-group">
{{ Form::label('beauty', 'Beauty & Fitness') }}
{{ Form::select('beauty', $beauty, null, array('multiple'=>'multiple','name'=>'beauty[]', 'class' => 'multiselect2 form-control')) }}
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-white">
<div class="panel-body">
<div class="col-md-12 col-sm-12">
<div class="form-group">
{{ Form::label('attractions', 'Activities & Attractions') }}
{{ Form::select('attractions', $attractions, null, array('multiple'=>'multiple','name'=>'attractions[]', 'class' => 'multiselect2 form-control')) }}
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-white">
<div class="panel-body">
<div class="col-md-12 col-sm-12">
<div class="form-group">
{{ Form::label('restaurants', 'Restaurant & Bars') }}
{{ Form::select('restaurants', $restaurants, null, array('multiple'=>'multiple','name'=>'restaurants[]', 'class' => 'multiselect3 form-control')) }}
</div>
</div>
</div>
</div>
</div>
And I am using this library to handle multiselect function
https://github.com/davidstutz/bootstrap-multiselect
in controller I just checking the data like this, and I not all my selection was submitted, its stop on specific limit but I don't know why?
public function store(Request $request)
{
dd($request);
}
Having so much options is not Ideal! However, I propose you look at your controller. Its possible that you paginate your result. Also it could be browser related. Until we see what you have done or what you seeing, we cannot give your an exact answer...only assumptions

Form Data Not Creating Array

I have a form which I use jQuery .cloneme to make duplicate elements. I have the form elements names as "xxxxx[]" so they should create an array once processed, but I'm only getting the first instance:
#extends('app')
#section('content')
<div class="row">
<div class="col-md-10 col-md-offset-1">
<h1>Create a New Jobsheet</h1>
<hr/>
{!! Form::open(['url' => 'jobsheets']) !!}
<div class="form-group">
{!! Form::label('customer','Customer') !!}
<select name="customer" size="1" class="form-control">
<option value="" disable selected>-- Select Customer --</option>
#foreach($customers as $c)
<option value="{{ $c->name }}">{{ $c->name }}</option>
#endforeach
</select>
</div>
</div>
</div>
<br/>
<div class="row">
<div class="col-md-5 col-md-offset-1">
<div class="form-group">
{!! Form::label('travel','Travel Description: ') !!}
{!! Form::text('travel',null,['class' => 'form-control']) !!}
{!! Form::label('travelduration','Travel Duration: ') !!}
{!! Form::input('number','travelduration',null,['class' => 'form-control','step'=>'any']) !!}
</div>
</div>
<div class="col-md-4 col-md-offset-1">
<div class="form-group">
{!! Form::label('mileage','Mileage: ') !!}
{!! Form::input('number','mileage',null,['class' => 'form-control','step'=>'any']) !!}
</div>
</div>
</div>
<br/>
<div id="product">
<div class="clonedInput" id="input1">
<div class="row">
<div class="col-md-6 col-md-offset-1">
{!! Form::label('product[]','Product: ') !!}
<select name="product[]" size="1" id="product1">
#foreach($products as $p)
<option value="{{ $p->name }}">{{ $p->name }}</option>
#endforeach
</select>
</div>
<div class="col-md-2 col-md-offset-1">
{!! Form::label('prodquant[]','Product Quantity: ') !!}
{!! Form::input('number','prodquant[]','1', ['class' => 'form-control', 'id' => 'prodquant1', 'step' => 'any'])
!!}
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-1">
{!! Form::label('proddescription[]','Description: ') !!}
{!! Form::textarea('proddescription[]',null,['class' => 'form-control','id' => 'proddescription1']) !!}
</div>
</div>
</div>
</div>
<button class="cloneme" rel="product">Add Product</button>
<div class="form-group">
{!! Form::submit('Create Jobsheet', ['class' => 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
#endsection
#section('scripts')
<script>
//should clone and add on to the bottom of the scorer sections in the game edit form
$(function() {
$('.cloneme').click(function(e){
e.preventDefault();
var id = $(this).attr("rel");
var clone_item = $("#" + id).find(".clonedInput");
clone_item.clone().removeAttr("id").removeClass("clonedInput").appendTo('#' + id);
});
});
</script>
#endsection
Can someone please tell me why when I create a duplicate the form data doesn't go into an array?
You can debug valid post data with chrome Inspector (F12), tab Network.
In code you dump all as below
dd($request->all());
//or
dd(\Input::all());
If everything works fine, you can loop data by
foreach($request->get('product') as $key=>$product) {
$qty = $request->get('prodquant')[$key];
}
Edit:
It should be:
#section('content')
{!! Form::open.... !!}
// all form inputs
{!! Form::close() !!}

Categories