Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to update particular column of mysql database

Tags:

php

mysql

laravel

I am not able to update a particular column of my database. In my database there is a "conditions" column which has a default value of "pending". I want to update this column with value "accept", but I am unable to do so.

My routes.php

Route::get('accept/{id}',array(
    'as'=>'accept-product',
    'uses'=>'GoodsController@updateProduct
));

My controller:

public function updateProduct($id) 
{
    $product = Products::findOrFail($id);
    $product->conditions = 'accept';
    $product->save();
}

My view:

@foreach($product as $productAccept)
    <a href="{{URL::route('accept-product')}}/{!! $productAccept->id !!}   ">Accept</a>
@endforeach

When I clicked accept button, the url is like this

http://localhost/project/public/accept/{id}

Which I want like this:

http://localhost/project/public/accept/7

I mean I am unable to replace {id} to integer like 7,8 etc.

Is something wrong in my routes?

like image 861
Ranjeet Karki Avatar asked Dec 19 '22 03:12

Ranjeet Karki


2 Answers

Your defined route expects one extra parameter - id. You need to pass the product id in the route function as extra parameter like this:

 <a href="{{URL::route('accept-product', ['id' => $productAccept->id])}}">Accept</a>
like image 56
Sh1d0w Avatar answered Jan 15 '23 04:01

Sh1d0w


use url as that

<a href="{!! URL::to('accept/$productAccept->id') !!}">Accept</a>
like image 44
Imtiaz Pabel Avatar answered Jan 15 '23 06:01

Imtiaz Pabel