Hello, I am trying to enter a data to a field of my database in Laravel, the problem is that I get Array to string conversion , the code is as follows:
$credentials='Lab Catálisis';
if ($credentials =='Lab Catálisis') {
$lab = new tbl_lab();
$lab->lab_ceco = $request->ceco;
$lab->lab_direccion = $request->direccion;
$lab->lab_lider = $request->lider;
$lab->lab_usu_id = DB::select("SELECT max(usu_id) FROM tbl_usuario");
$lab->save();
return view('login');
}
The DB brings me the data as an array, how could I convert that array that the query brings me to an integer to be able to enter it into my field.
Thanks.
You have forgotten to collect the data of your query to the database:
You must collect it as follows:
Anyway, I advise you to use the laravel orm; eloquent , with eloquent it would be something like this:
In this case it is not necessary to use a raw query , you can use the equivalent methods of the query builder:
If for some reason said method does not deliver the unique data, you can access the data with object or array syntax,