Mohammad Tariq
Mohammad Tariq

Reputation: 101

Call a Controller Function Directly from view button

Problem I want to call My controller function from my blade button and I face some errors.

(ErrorException in UrlGenerator.php line 603: Action App\Http\Controllers\OrderController@Orderfun not defined. (View: C:\Users\MalikTariq\Project\resources\views\admin.blade.php))

My controller function is:

     public function Orderfun(){
        // $data=Orders::all();
        // foreach ($data as $key => $value) {
        //     echo "value is =".$value;
        echo "My name is Malik ";
                           }

Route is:

Route::get('Order/Orderfun', 'AdminController@Orderfun');

My blade code is:

<a href="{{action('OrderController@Orderfun')}}"><button type="button"      class="btn btn-danger" id="bt1">View Orders</button></a>

Upvotes: 2

Views: 3190

Answers (1)

Laravel User
Laravel User

Reputation: 1129

Use route method instead of action method in href attribute of a element in your view.

Upvotes: 0

Related Questions