How to Pass $val->id
in Laravel URL Parameter. I use Following Code. Its Return Error
href="{{url('/dashboard/medicinepending/{{$val->id}}')}}"
$request->id; You can get id from POST method like this. public function getDetail(Requests $rq){ $product = Product::where('id',$rq->id)->get(); } .
Route::post('job/{job_id}/upload/file', 'DataController@read_xsl'); Or you can send the {job_id} as form data to the route and then do a Request to get the job_id. i.e. If your parameter name has changed from 'id' to anything, you should change both of 'id' name in route and controller to work correctly.
You can send the variable as route parameter. To do this change your <a> tags like this. Now pass this $course_id to your form view. To submit this variable with your other fields you can add this as hidden input field.
Try this:
href="{{ URL('/dashboard/medicinepending/'.$val->id )}}"
As previously explained the way in which to build a URL within a blade template you can use the url
helper; for your example this would work:
{{ url('dashboard/medicinepending/', [$val->id] }}
It is not advised to use url
, route
or even action
when building a url for your views. This is because the URLs will not change, if they do you should have 301 redirects set-up in order for your SEO score to remain valid and good.
So simply do something like:
<a href="/dashboard/medicinepending/{{ $val->id }}">
But if you REALLY want to use a wrapper then url
is the second best thing.
The only purpose of these helpers are for e-mails or commands via artisan
, when fired the cron does not know about the URL only what is defined in the config: app.url
The way in which URLs are built with laravel is by prepending the string with the value of app.url
config; found: inside config/app.php
This is mainly for the CLI, when you have cron processes running and generating e-mails from a queue with links, therefore this could be used within your application. Otherwise do not use it at all.
Using the url
helper is good because you can change the value of the app.url
config by your own Service Provider. This is very useful for when you have a website in multiple languages and/or load a sites language based on the domain name; example:
As also mentioned you can build urls from a route; this is only valid if you name your routes which is not always the case.
{{ route('name.route', ['id' => $val->id] }}
This will find the route by the name route.name and then parse that end-point through app('url')
which happens to be the UrlGenerator - so this is no better than the url
helper - do not go out of your way to name all routes - that is bad practice.
Another practice mentioned which is also not a good idea is using action
by providing the class and action to find a route:
{{ action('MyController@show', $val->id) }}
This is a bad idea unless MyController
is actually an interface NOT a physical class, in that you need Inversion of Control to inject the class that implements MyController otherwise your application will not conform to the S.O.L.I.D Principle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With