Try $movies= Movie::with('MovieAka')->get();
Oct 26, 2017
7
Level 24
query and show all movies info with aka name
ok i follow the Laravel doc setup the OneToMany Relationships
// Movie model
class Movie extends Model
{
protected $table = 'movies';
protected $guarded = [];
public function movieAka()
{
return $this->hasMany('App\MovieAka', 'movie_id');
}
}
// movie_aka table
id | movie_id | aka_name
// MovieAka model
class MovieAka extends Model
{
protected $table = 'movie_aka';
protected $guarded = [];
public function movie()
{
return $this->belongsTo('App\Movie', 'movie_id');
}
}
// MovieController
class MovieController extends Controller
{
public function listMovieWithAkaName(Request $request)
{
$movieAkaName = Movie::find(5)->movieAka;
return $movieAkaName;
}
}
all is worked fine, but what about i want to show all the movies info with aka name in the same page look like imdb.com , after u search a movie, on the result page will show the aka another name so i want the result look like this:
movie name: abcdef (aka ccc, aaa, bbb)
movie name: xyz (this may be empty)
Thx
Level 10
Please or to participate in this conversation.