Object of class stdClass could not be converted `how can i fix this Error Object of class stdClass could not be converted to string
<?php
namespace App\Http\Livewire;
use App\Models\Movie;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Livewire\Component;
class MovieList extends Component
{
public function render()
{
return view('livewire.movie-list',[
'movies' => DB::table('movies')->where('user_id', 1)->paginate(10),
]);
}
}
movie view blade
@foreach( $movies as $movie )
<a href="{{ route('movies.show', $movie) }}" > {{ $movie->title }} </a>
@endforeach
CodePudding user response:
Try by using Eloquent query instead. Since you are using a raw expression, some methods may not be available.
Try with
<?php
namespace App\Http\Livewire;
use App\Models\Movie;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Livewire\Component;
class MovieList extends Component
{
public function render()
{
return view('livewire.movie-list',[
'movies' => Movie::where('user_id', 1)->paginate(10),
]);
}
}