banda
banda

Reputation: 402

did not route page to payment blade file in laravel 5.6

in My laravel 5.6 app I have following route link to payment.blade.php file in payments view files,

<a class="btn btn-primary" href="{{route('payments.payment',$vehicles->id)}}" role="button">Go Premium</a>

route for this page is,

Route::get('myads/{id}/edit/payment', function(){
    return view('payments.payment');
})->name('payments.payment');

and in payment.blade.file i have following form action,

<form method="post" action="{{route('payments.payment', ['id' => $vehicles->id])}}">
{{csrf_field()}}

it is execute route is,

Route::get('/add-order/{id?}', 'PController@addOrder')->name('payments.payment'); 

normaly I need go payment blade file via above link and form submit using blade submit buttons. but here my application when I click go premium button to visit payment blade file it is not redirect to payment buttons. it is execute payment blade file form action with out displaying payment blade file. how can I fix this problem?

please see my edited routes and form action

Route::get('myads/{id}/edit/payment', function(){
    return view('payments.payment');
})->name('payments.viewpayment');

and

Route::post('/add-order/{id?}', 'PController@addOrder')->name('payments.payment');

and form action

<form method="post" action="{{route('payments.viewpayment', ['id' => $vehicles->id])}}">

but now got this error,

(1/1) MethodNotAllowedHttpException 

how can fix this?

adOder function

 public function addOrder(Request $request,$id = null)
{

    DB::table('vehicles')
            ->where('id', $id)
            ->update(['adtype' => '1']);
}

current codes

Route::get('myads/{id}/edit/payment', function($vehicle_id){
return view('payments.payment',compact('vehicle_id'));
})->name('payments.payment');

Route::post('/add-order/{id}', 'PController@addOrder')->name('payments.payment');

link to payment blade

<a class="btn btn-primary" href="{{url('myads/'.$vehicles->id.'/edit/payment')}}" role="button">Go Premium</a>

form action,

<form method="post" action="{{route('payments.payment', ['id' => $vehicle_id])}}">

and controller,

public function addOrder($id = null)
{
    DB::table('vehicles')
            ->where('id', $id)
            ->update(['adtype' => '1']);
}

Upvotes: 0

Views: 210

Answers (2)

Leena Patel
Leena Patel

Reputation: 2453

You can use same name for get and post methods for same view

In your anchor tag

<a class="btn btn-primary" href="{{url('myads/'.$vehicles->id.'/edit/payment')}}" role="button">Go Premium</a>

In your Routes file

Route::get('myads/{id}/edit/payment', function($id){
return view('payments.payment',compact('id'));
})->name('payments.payment');

Route::post('/add-order/{id}', 'PController@addOrder')->name('payments.payment'); 

And in your form tag

<form method="post" action="{{route('payments.payment', ['id' => $id])}}">

You need to Redirect back with success message in your function

public function addOrder($id = null)
{
    DB::table('vehicles')
        ->where('id', $id)
        ->update(['adtype' => '1']);

    return redirect()->back()->with('success', 'Successfully added');
}

Upvotes: 2

Bhargav Chudasama
Bhargav Chudasama

Reputation: 7171

try with diff name routes

Routes

Route::get('myads/{id}/edit/payment', function(){
    return view('payments.payment');
})->name('payments.viewpayment');
Route::post('/add-order/{id?}', 'PController@addOrder')->name('payments.payment'); 

Action

<a class="btn btn-primary" href="{{route('payments.viewpayment',$vehicles->id)}}" role="button">Go Premium</a>
<form method="post" action="{{route('payments.payment', ['id' => $vehicles->id])}}">
{{csrf_field()}}

Upvotes: 1

Related Questions