Im new in laravel and I dont want to waste my time to finding away the eloquent script to running my complex query script, is there is a way for me. for just write the query script (select, insert, update, delete) I have, to the laravel project and everything is work as I want?
this bellow my sample code for select data, I want to replace the eloquent with pure query script
function getClaim(){
$data_claim = \App\ClaimModel::all();
return response()->json(
[
"message" => $data_claim
]
);
}
$users = DB::select('select * from users where active = ?', [1]);
return view('user.index', ['users' => $users]);
Do this
Insert query
$insert = DB::insert("insert into some_table (col1, col2, col3) values ('value1', 'value2', 'value3')");
Select query
$results = DB::select("select * from some_table where some_col = 'some_value'");
Update query
$update = DB::update("update some_table set col1 = ? , col2 = ? where col3 = ?", ['value1' , 'value2', 'value3']);
Delete query
$delete = DB::delete('delete from some_table where col = ?',['value']);
You can also delete multiple rows at a time. Like
$delete = DB::delete('delete from users where id = ?',[1, 2, 3]);
You can do this like
For Select query
$users = DB::select('select * from users where active = ?', [1]);
For Update query
$affected = DB::update('update users set votes = 100 where name = ?', ['John']);
For Delete query
$deleted = DB::delete('delete from users');
For Insert query
DB::insert('insert into users (id, name) values (?, ?)', [1, 'Dayle']);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.