I have one route which is accepting one argument perfectly as
Route::get('view-request/type/{type}/id/{id}', 'CustomerReqController#testing')->name('request.manage');
and also call it in blade by this
<a href="{{route('request.manage',['type'=>'new','id'=>'data'])}}"
and the controller is
public function testing(Request $request,$type,$id){
dd($request->all());
}
it gives me error
Missing required parameters for [Route: request.manage] [URI: admin/view-request/type/{type}/id/{id}]. (View: /var/www/html/ehs_crm_laravel/resources/views/common/navbar.blade.php) (View: /var/www/html/ehs_crm_laravel/resources/views/common/navbar.blade.php) (View: /var/www/html/ehs_crm_laravel/resources/views/common/navbar.blade.php)
What am i doing wrong?
use:
<a href="{{ route('request.manage', ['type' => 'new', 'id' => 'data']) }}">
you can get your route parameter by simply using this code. hope this will work for you. for Get and Post method both.
public function testing(Request $request)
{
$type= $request->type;
$id= $request->id;
}
follow steps this code is working to me.
1 : declare route
Route::get('view-request/type/{type}/id/{id}', 'UserController#index')->name('request.manage');
2: create link
Register
3: get data in controller
public function index($type,$id,Request $request){
echo $type;
echo $id;
}
Related
I encounter a problem on Laravel, I followed the Bootcamp step by step and it was nice, very clear I finished it entirely,
I'm facing trouble when I try to reproduce it on a project of my own, everything goes cool until I try to implement the "edit" part see: https://bootcamp.laravel.com/blade/editing-chirps
I'm getting this error : Missing required parameter for [Route: Region.update]
I've been looking for some times but didn't find anything that worked for me, here is the code :
Controller :
public function edit(Region $region)
{
return view('regions.edit', [
'region' => $region,
]);
}
public function index()
{
$regions = Region::all();
return view('regions.index', [
'regions' => $regions,
]);
}
public function update(Request $request, Region $region)
{
$validated = $request->validate([
'name' => 'required|string|max:255',
]);
$region->update($validated);
return redirect(route('Region.index'));
}
Index view where I'm passing the data :
<x-dropdown-link :href="route('Region.edit', $region)">
<img src={{url("build/img/edit.png")}} width="40">
</x-dropdown-link>
Edit view specifically where problems happens.
<form method="POST" action="{{ route('Region.update', $region) }}">
Web route file
Route::resource('Region',RegionController::class)
->only(['index', 'create', 'store', 'edit', 'update'])
->middleware(['auth', 'verified']);
When I click the link in the index view, I'm redirect on the right link : http://localhost/Region/5/edit ( 5 is an exemple of id ).
But the error from the title appears.
I tried this because I read it here :
<form method="POST" action="{{ route('Region.update', ['Region' => $region]) }}">
But it didn't change anything.
Any help would be really appreciate.
Thank you for advance
Laravel Resource is case sensitive I think... So, we need to name parameter converter with uppercase like in resource name.
public function edit(Region $Region);
public function update(Request $request, Region $Region);
I have method in my controller (singleProduct):
public function singleProduct($slug)
{
$product= Product::where('slug','=', $slug)->first();
return view('public.product.show')->withProduct($product);
}
And my route is:
Route::get('/{category}/{slug}',['as' => 'single.product', 'uses' => 'LinkController#singleProduct']);
My code in view:
{{$product->title}}
Though i have passed both required parameter for route.My route is returning an error of:
Missing required parameters for [Route: single.product] [URI: {category}/{slug}].
The correct way for defining route params is like:
route('single.product', ['category' => $product->category, 'slug' => $product->slug])
So your route in view will be as:
{{$product->title}}
Docs
In route definition you have slug and category, but in method you get actually just the slug, so maybe adding $category to singleProduct will help:
public function singleProduct($category, $slug)
{
$product= Product::where('slug','=', $slug)->first();
return view('public.product.show')->withProduct($product);
}
I need to pass an additional parameter($uid) from my index.blade.php to my edit.blade.php by clicking on a button.
My index.blade.php:
Edit
My FlyersController:
public function edit($id, $uid)
{
return view('backend.flyers.edit')->withUid($uid);
}
With the code above I get an error: "Missing argument 2 for App\Http\Controllers\FlyersController::edit()"
What am I doing wrong here?
The error is not throwing from the action method. It is coming from route for that URL.
Check the URL for passing argument to the the controller.
If this is the your desire URL localhost:8000/backend/flyers/10/edit?%24uid=1 then the second argument is in $request variable not in controller function argument.
You should pass an array into action() helper:
action('FlyersController#edit', ['id' => Auth::user()->id, 'uid' => 1])
Ok,
the only way I can solve this is by using the following in My FlyersController:
public function edit(Request $request, $id)
{
return view('backend.flyers.edit')->withRequest($request);
}
and access then the uid with {{request->uid}} in my view.
If anybody has a better solution for this, let me know.
Use this code
return view('backend.flyers.edit', ['var1' => $var1, 'var2' => $var2]);
That will pass two or more variables to your view
This is code snippet from my view file.
#foreach($infolist as $info)
{{$info->prisw}} / {{$info->secsw}}
#endforeach
Here is my route which I defined inside route file
Route::get('switchinfo','SwitchinfoController');
I want to pass two values inside href tag to above route and retrieve them in controller. Can someone provide code to do this thing?
Since you are trying to pass two parameters to your controller,
You controller could look like this:
<?php namespace App\Http\Controllers;
class SwitchinfoController extends Controller{
public function switchInfo($prisw, $secsw){
//do stuffs here with $prisw and $secsw
}
}
Your router could look like this
$router->get('/switchinfo/{prisw}/{secsw}',[
'uses' => 'SwitchinfoController#switchInfo',
'as' => 'switch'
]);
Then in your Blade
#foreach($infolist as $info)
Link
#endforeach
Name your route:
Route::get('switchinfo/{parameter}', [
'as'=> 'test',
'uses'=>'SwitchinfoController#function'
]);
Pass an array with the parameters you want
<a href="{{route('test', ['parameter' => 1])}}">
{{$info->prisw}} / {{$info->secsw}}
</a>
and in controller function use
function ($parameter) {
// do stuff
}
Or if don't want to bind parameter to url and want just $_GET parameter like url/?parameter=1
You may use it like this
Route::get('switchinfo', [
'as'=> 'test',
'uses'=>'SwitchinfoController#function'
]);
function (){
Input::get('parameter');
}
Docs
You can simply pass parameter in your url like
#foreach($infolist as $info)
<a href="{{ url('switchinfo/'.$info->prisw.'/'.$info->secsw.'/') }}">
{{$info->prisw}} / {{$info->secsw}}
</a>
#endforeach
and route
Route::get('switchinfo/{prisw}/{secsw}', 'SwitchinfoController#functionname');
and function in controller
public functionname($prisw, $secsw){
// your code here
}
LARAVEL 5.1
I want to edit my table which having ID and TktID.
I want to pass this two parameters to edit method of my TestController.
My link:
<a href="/sig/edit?id={{$value->id}}&ticketid={{$value->ticketid}}" title="Edit signature">
My route.php
Route::get('sig/edit{id}{ticketid}','TicketsController#edit');
edit method of controller:
public function edit($id, $ticketid)
{
//
}
How do I pass here two arguments in route.php to controller.
You forget end bracket
You have error in your routes.php file:
Route::get('sig/edit{id}{ticketid}', 'TicketsController#edit');
Should be:
Route::get('sig/edit/{id}/{ticketid}', 'TicketsController#edit');
Notice the forward slash after edit and id.
And in the view it should be either of the following:
<a href="{{ url('sig/edit/ ' . $value->id . '/' . $value->ticketid .')}}" title="Edit signature">
Or
<a href="/sig/edit/{$value->id}/{$value->ticketid}" title="Edit signature">
I hope this helps you out. Cheers.
Route
Route::get('sig/edit{id}{ticketid}','TicketsController#edit')->name(sig.edit);
link
<a href="{{route('sig.edit',[$value->id,$value->ticketid])}}" title="Edit signature">
<a class="getValues" href="/sig/edit" title="Edit signature"/>Edit</a>
<input type="hidden" id="id" name="id" value"={{$value->id}}"/>
<input type="hidden" id="ticketid" name="ticketid" value="{{$value->ticketid}}"/>
jQuery(document).ready(function(){
var $id=jQuery('#id').val();
var $ticketid=jQuery('#ticketid').val();
jQuery('getValues').on('click',function(){
$.ajax({
url:'yourController/controller'sFunction',
data:{'id':$id,'ticketid':$ticketid},
}).success(function(response){
alert(rseponse);
});
})
});
paste this line of code as first line in your controller's function ...
$inputs = Input::all();
and get values of input like
echo $ticketid=$inputs['ticketid'];
echo "<br/>";
echo $id=$inputs['id'];
In my case, I am passing two parameters like this:
ROUTES
Route::get('/add/{debitid}/{creditid}',
['as'=>'loan_add',
'uses'=>'LoanController#loanset']);
In LoanController
public function loanset($debitid, $creditid)
{
$debit_user= UserModel::findOrFail($debitid);
$credit_user= UserModel::findOrFail($creditid);
return view('load.add',compact('debit_user','credit_user'));
}
This example might be helpful.
I found this way to keep your URL the same way and access multiple parameters
<a href="/sig/edit?id={{$value->id}}&ticketid={{$value->ticketid}}" title="Edit signature">
Route
Route::get('sig/edit', 'TicketsController#edit');
Access the parameter values in the controller
Controller
public function edit(){
$id = Input::get('id');
$ticketId = Input::get('ticketid');
}
Note: import Input in controller
use Illuminate\Support\Facades\Input;
in routes/web.php file - This one works for me.
Route::any('/documents/folder/{args?}', function($args){
$args = explode('/', $args);
return $args;
})->where('args', '(.*)');
It should handle every argument/parameter now.
Hope it works !
As you are passing the parameters like this ?name=value, you dont have to set up the route for it , you can directly access it in your controller by Dependency injection
you have to add this above your class
use Illuminate\Http\Request;
Then in controller inject it & fetch the parameter values by name:
public function edit(Request $request)
{
//
$id= $request->id;
$tkt= $request->tkt_id;
}