Laravel Array to String Conversion

How to convert array to string in laravel?

 print_r($request->education); //It is an array print

$str_json = json_encode($request->education); //array to json string conversion
echo $str_json; // printing json string

print_r(json_decode($str_json)); //printing array after convert json string to array

exit; // exiting further execution to check resutls

laravel Error: Array to string conversion

As you have pivot table for roles than you dont need role_id column in your users table

public function store(Request $request)
{
$this->validate($request, [
'name'=> 'required|string|max:225',
'status'=> 'required',
'role_id'=> 'required|array',
'email'=> 'required|string|email|max:225|unique:users',
'password'=> 'required|string|min:6|confirmed'
]);

$password = Hash::make($request->password);
// dd($request->all());

$user = new User;
$user->name = $request->name;
$user->status = $request->status;
$user->email = $request->email;
$user->password = $password;
$user->remember_token;
$user->save();

foreach($request->input('role_id') as $role)
{
$user->assign($role);
}
// $user->roles()->sync($request->roles, false);
return back()->with('message', 'User added successfully!!');
}

Error Array to string conversion when use Authentication in laravel

there should be one table name in model. please remove array and make it as string, or you can check Laravel Model documentation for more clarification.

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class UserModel extends Authenticatable
{
use Notifiable;

protected $guard = 'admin';
protected $table = 'users'; //change this variable type
protected $fillable = ['name','email','password'];
protected $hidden = ['password', 'remember_token',];

}

or please provide proper error description.

Laravel 8: Array to string conversion while calling route:list

Route::resource is expecting a string for the second argument, not an array.

Route::resource('articles', ArticleController::class);

Remove the call to namespace for the group, you don't need any namespace prefix because you are using the Fully Qualified Class Name, FQCN, to reference the Controllers.

Route::prefix('admin')->group(function () {
Route::get('/admin/panel', [PanelController::class, 'index']);
Route::resource('articles', ArticleController::class);
});

laravel return array to string conversion error

I think the problem is here:

$order->order_data = $cartData;

$cartData is an array and cannot be saved into database directly.

That's why you got Array to string conversion error.



Related Topics



Leave a reply



Submit