0

please assist to convert this SQL query into laravel format

"update user_names  set assignedTo = '09874',Assigned=1 where timePackage='1 hr' and Assigned=0  order by id limit 1"
1
  • What do you mean by "Laravel format"? Do you mean Eloquent? Commented Nov 29, 2020 at 20:12

1 Answer 1

1

Try this:

use Illuminate\Support\Facades\DB;

DB::table('user_names')
    ->where('timePackage', '1 hr')
    ->where('Assigned', 0)
    ->orderBy('id')
    ->limit(1)
    ->update([
        'assignedTo' => '09874',
        'Assigned' => 1,
    ]);

See Laravel docs for more info.

Sign up to request clarification or add additional context in comments.

4 Comments

thanks for the answer. I have adjusted my controller but it is not updating the DB.this is the Controller <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class UserNamesController extends Controller { public function index() { DB::table('user_names') ->update([ 'assignedTo' => '088', 'Assigned' => 1, ]) ->where('timePackage', '1 hr') ->where('Assigned', 0) ->orderBy('id') ->limit(1); } }
@user3736334 my bad, you must call update at last. edited my answer.
thanks now I get an error in postman 419 unknown status and no update in db I don't know what am doing wrong.
thanks alot your code workd I realized the error was because of csrf. issues

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.