Skip to content
Advertisement

Laravel question, How to use _GET on Blade

I have a question that I cant solve at this moment.

I have and URL like this: https://www.example.com/schedule/2020-02-26

i put the date on the URL with the next function:

   public function newdate($datevar)
    {       
        $Dates = Dates::all();
        return view('schedule', compact('Dates'), ['Dates' => 
     $Dates]);
    } //

In this example $datevar is equal to “2020-02-26”

My question is, How can I show the $datevar in my blade? Im trying with {{$datevar}} but I get an error.

To put the datevar on my function I use and other function as Request:

public function addnewdate(Request $request){
   $datevar = $request->input('newdate');

    return redirect()->to('schedule/'.$datevar);
}

Thanks for your help

Advertisement

Answer

The solution is to register the URL format in the web.php file. In that file, add this line:

Route::get('/schedule/{date}', [ControllerName::class, 'addnewdate']);

Now, whenever the the controller method is called, it’ll pass the date as an argument to your addnewdate method, which you need to restructure like this:

public function addnewdate($date){
    //Do sth with the date
}
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement