1

I created a controller with resource. I made a custom function inside it however when I use it as a route in my blade.php it says that it is not defined.

Any help with the error and explanation about it is highly appreciated!!

Blade

    <div class="modal fade" id="issueModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
        <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
            </button>
        </div>
        <div class="modal-body">
            <form action="{{route('inventory.deduct')}}" method="post">


        </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary">Save changes</button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            </div>
            </form>
        </div>
    </div>
</div>

custom function inside controller

public function deduct(Type $var = null)
{
    dd("test");
}

Route

Route::resource('inventory', 'InventoryController');
kwestionable
  • 496
  • 2
  • 8
  • 23

2 Answers2

3
Route::post('/inventory/deduct', 'InventoryController@deduct')->name('inventory.deduct');

Add this to your Routes in Web.php file. Resource only creates the default routes for controller, not the custom ones.

Ahmad Karimi
  • 1,285
  • 2
  • 15
  • 26
0

Resource route is for index, create, store, show, edit, update and destroy. Your new route is not defined in a resource route. So you have to create a new route to use it. Add this route above your resource route in web.php file

Route::post('inventory/deduct', 'InventoryController@deduct')->name('inventory.deduct');

This will make your route and you can use it in your form and you can make the function to your controller to do what you want to do.

zahid hasan emon
  • 6,023
  • 3
  • 16
  • 28