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
Regex to Check the String Contains Only Letter and Numbers But Not Only Numbers
Php to View Pdf on Web Page and Disable User to Download
Converting Timestamp to Time Ago in PHP E.G 1 Day Ago, 2 Days Ago...
Should We Ever Check For MySQLi_Connect() Errors Manually
Returning Json from a PHP Script
Call to Undefined Method MySQLi_Stmt::Get_Result
How to Configure Xampp to Send Mail from Localhost
Show a Number to Two Decimal Places
What Are Long-polling, Websockets, Server-sent Events (Sse) and Comet
How to Convert Array to Simplexml
PHP - Ssl Certificate Error: Unable to Get Local Issuer Certificate
MySQL Great Circle Distance (Haversine Formula)
How to Ping a Server Port With PHP
How to Get Data from Another Table Using Id from Another Table
Php Substring Remove Everything in a String After Certain Character
How to Get Multiple Value from Post Variable Using Same Name