3

In my route I have like this

Route::get('/library/{id?}', 'LibraryController@index')->name('library');

and returning my url to http://localhost/dmb/library/2017

In my blade how can I check and display if I have that 2017 in my url?

4
  • 1
    you can use $_GET Commented Oct 26, 2017 at 8:15
  • Which parameter will I call to get 2017 value? Commented Oct 26, 2017 at 8:16
  • You can get it in the controller and pass it as a parameters to the view (even if $_GET is possible in the view, it's better to use the $request->get() method inside a controller). If you need it everywhere, you can add it inside a middleware with view()->share('key','value') edit: here, you'll have in the prototype of your method index() the paremeters index(Request $request, $id) right ? so just when you return the view : return view('myview', ['id' => $id]) Commented Oct 26, 2017 at 8:17
  • Ok I got that I actually have more parameter passing from my eloquent collection but is there a way to get those parameter directly from blade? Commented Oct 26, 2017 at 8:21

1 Answer 1

9

this code will help you

if you want to get library then you should used

$segment = Request::segment(1);

for 2017 then used segment(2)

$segment = Request::segment(2);
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this is what I need

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.