Hello i'm still pretty new to this and learning, sorry if the answer is obvious. I'm doing a small project where I would show a list of movies and when you click on one it takes you to that movie's page where you can see more details.
Here is what I have so far:
Controller
public function getShow($id)
{
$arrayPeliculas= \DB::table('movies');
return view('catalog.show', ['arrayPeliculas' => Movie::all()]);
}
public function getEdit($id)
{
return view('catalog.edit', array('id'=>$id));
}
public function getIndex()
{
$arrayPeliculas= \DB::table('movies');
return view('catalog.index', ['arrayPeliculas' => Movie::all()]);
}
public function getCreate()
{
return view('catalog.create');
}
Index file where list of movies is show:
@foreach( $arrayPeliculas as $key => $pelicula )
<div class="col-xs-6 col-sm-4 col-md-3 text-center">
<a href="{{ url('/catalog/show/' . $key ) }}">
<img src="{{$pelicula->poster}}" style="height:200px"/>
<h4 style="min-height:45px;margin:5px 0 10px 0">
{{$pelicula['title']}}
</h4>
</a>
</div>
@endforeach
Details page
<div class="col-sm-4">
{{-- TODO: Imagen de la película --}}
<img src="{{$arrayPeliculas[1]->poster}}" style="height:200px"/>
</div>
<div class="col-sm-8">
{{-- TODO: Datos de la película --}}
<h1>{{ $arrayPeliculas[1]->title }}</h1>
<h3>Año: {{ $arrayPeliculas[1]->year }}</h3>
<h3>Director: {{ $arrayPeliculas[1]->director }}</h3>
<p><b>Resumen:</b>{{ $arrayPeliculas[1]->synopsis }}</p>
@if($arrayPeliculas[1]->rented==true)
<div>
<p><b>Estado:</b>Pelicula actualmente alquilado</p>
<button class="btn btn-danger" type="submit">Devolver Pelicula</button>
<button class="btn btn-warning" type="submit">Editar Pelicula</button>
<button class="btn btn-default" type="submit">Volver al listado</button>
</div>
@else
<div>
<p><b>Estado:</b>Pelicula Disponible</p>
<button class="btn btn-primary" type="submit">Alquilar Pelicula</button>
<a href="{{ url('/catalog/edit/' . $arrayPeliculas[0]->id ) }}"><button class="btn btn-warning" type="submit">Editar Pelicula</button></a>
<a href="/videoclub/public/catalog"><button class="btn btn-default" type="submit">Volver al listado</button></a>
</div>
@endif
</div>
So with index I was able to use a foreach that list all the movies and then send it to the correct page of that movie. On the details page though i'm not quite able to figure out how to get the id of that movie to show the relevant info. I tried using
$arrayPeliculas->poster
Then I tried putting the index which sort of works, but only shows the movie of that index no matter the page im in
$arrayPeliculas[1]->poster
I imagine it should be something like
$arrayPeliculas[$id]->poster
but i'm not able to figure out how to get the id for the selected movie.