Variable in all controller and view fullcalendar laravel 5.6
I use fullcalendar in my web site in laravel 5.6 and it working but when i change view i have this problem :
Undefined variable: calendar_details
In my view layout.app i have this :
{!! $calendar_details->script() !!}
Can i define this var in all controller and view to avoid all problem ?
This is my EventsController.php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use IlluminateSupportFacadesRedirect;
use AppHttpControllersController;
use Auth;
use Validator;
use AppEvents;
use Calendar;
class EventsController extends Controller
{
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)
);
}
$calendar_details = Calendar::addEvents($event_list);
return view('events', compact('calendar_details'));
}
public function addEvent(Request $request){
$validator = Validator::make($request->all(), [
'event_name' => 'required',
'start_date' => 'required',
'end_date' => 'required',
]);
if ($validator->fails()){
Session::flash('warning', 'Veuillez entrer des informations valide');
return Redirect::to('/events')->withInput()->withErrors('warning');
}
$event = new Events;
$event->event_name = $request['event_name'];
$event->start_date = $request['start_date'];
$event->end_date = $request['end_date'];
$event->save();
Session::flash('success', 'Evènement ajouté avec succès');
return Redirect::to('/events');
}
}
and this is my Events.php :
<?php
namespace App;
use IlluminateDatabaseEloquentModel;
class Events extends Model
{
protected $fillable = [
'event_name', 'start_date', 'end_date'
];
}
from Laravel Questions and Answers https://laravelquestions.com/laravel/variable-in-all-controller-and-view-fullcalendar-laravel-5-6/
via Lzo Media
No comments:
Post a Comment