Reputation: 126
I get this error when i try loading blade.php
Action App\Http\Controllers\InventoryItemController@change not defined.
I have change function in InventoryItemController
public function change($new_status)
{
//
}
This started when I wanted to make button
<a href="{{action('InventoryItemController@change', $inventoryitem['new_status'])}}"class="btn btn-info">Confirm Change</a>
I did everything same when i made Edit button and that button works normally.
UPDATE 1
My button looks like this now
<a href="{{route('change', [$inventoryitem['new_status'],
$inventoryitem['asset_id']])}}"class="btn btn-info">Confirm Change</a>
and my change function is this
public function change($new_status, $asset_id)
{
$asset = Asset::find($asset_id);
$asset->status = $new_status;
return redirect('showasset', compact('asset','asset_id'));
}
and my route in web is like this
Route::get('change/{$new_status}/{$asset_id}','InventoryItemController@change')->name('change');
But after i click button it just redirect me to url .../change/4/1 and that's it. Nothing changes.
Upvotes: 1
Views: 672
Reputation: 126
Final error was in my route
Route::get('change/{$new_status}/{$asset_id}','InventoryItemController@change')->name('change');
It should be like this
Route::get('change/{new_status}/{asset_id}','InventoryItemController@change')->name('change');
After that change everything is working flawlessly. Thank you for your help guys!
Upvotes: 0
Reputation: 210
Define your controller's method in route file as following:
Route::get('url/{new_status}',InventoryItemController@change);
Answer on UPDATE 1
public function change($new_status, $asset_id)
{
$asset = Asset::find($asset_id);
$asset->status = $new_status;
$asset->save();
return view('your_view_path',compact('variable1','variable2'));
}
Upvotes: 1
Reputation: 15951
Using Action
is deprecated in Laravel
You can use routes instead.
Define Routes in your routes files (/routes/web.php) like.
Route::get('change/{status}','InventoryItemController@change')->name('change');
and then in your view
<a href="{{route('change', $inventoryitem['new_status'])}}"class="btn btn-info">Confirm Change</a>
In your controller use.
public function change ($status){
// rest of the function.
}
Hope this helps
Upvotes: 3