Answer the question
In order to leave comments, you need to log in
Why is variable not defined in laravel 5.1?
I can’t understand why laravel swears that the variable is not defined
The whole code of the productList.blade.php file:
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="btn btn-block"><a href="{{ route('product.create') }}"><h2>Add New Product</h2></a></div>
@foreach( $allProducts as $product )
<hr>
<div class="row">
{!! HTML::linkRoute('product.edit', 'Edit', array($product->id), ['class'=>'btn btn-default col-xs-2']) !!}
{!! Form::open(['route' => ['product.destroy', $product->id], 'method' => 'delete']) !!}
<input class="btn btn-default col-xs-2" type="submit" value="Удалить" />
{!! Form::close() !!}
</div>
<div><h1>{!! HTML::linkRoute('product.show', $product->title, array($product->id)) !!}</h1></div>
<div>{{ $product->description }}</div>
<div class="pull-right"><em>{{'Опубликовал -'. $product->author }}</em>
</div>
@endforeach
{!! Form::open(['route' => ['product.destroy', $product->id], 'method' => 'delete']) !!}
<input class="btn btn-default col-xs-2" type="submit" value="Удалить" />
{!!Form::close() !!}
</div>
</body>
</html>
public function index()
{
$allProducts = Product::all();
return view('products.productList', compact('allProducts'));
}
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $table = 'products';
protected $fillable = [
'title',
'description',
'author',
'image'
];
}
Answer the question
In order to leave comments, you need to log in
You are trying to use the $product variable behind a loop. Need like this:
<div class="pull-right"><em>{{'Опубликовал -'. $product->author }}</em> </div>
{!! Form::open(['route' => ['product.destroy', $product->id], 'method' => 'delete']) !!}
<input class="btn btn-default col-xs-2" type="submit" value="Удалить" />
{!!Form::close() !!}
@endforeach
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question