Answer the question
In order to leave comments, you need to log in
How to bind a parameter to another table?
The error itself:
Parsing the error:
There is a Book model in which the links are registered:
public function categories(){
return $this->belongsTo(Category::class, 'category_id');
}
public function publishers(){
return $this->belongsTo(Publisher::class, 'publisher_id');
}
public function index()
{
$products = Book::paginate(10);
return view('admin.product.product.index', compact('products'));
}
public function up()
{
Schema::create('books', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->date('published')->nullable();
$table->float('price');
$table->string('description')->nullable();
$table->boolean('available');
$table->string('author');
$table->integer('category_id')->nullable();
$table->integer('publisher_id')->nullable();
$table->integer('country_id')->nullable();
$table->timestamps();
});
}
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}
@foreach($products as $product)
<tr class="table-dark">
<td>{{$product->title}}</td>
<td>{{$product->author}}</td>
<td>{{$product->publishers->name}}</td>
<td>{{$product->categories->name}}</td>
<td>{{$product->count}} шт.</td>
<td>{{$product->price}} руб</td>
<td>
<form action="{{route('admin.product.destroy', $product)}}" method="POST"class="d-inline">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">delete</button>
</form>
<a href="{{route('admin.product.edit', $product)}}" class="btn btn-warning">edit</a>
<a href="{{route('admin.product.show', $product)}}" class="btn btn-info">overview</a>
</td>
</tr>
@endforeach
</tbody>
</table>
{{$products->links()}}
Answer the question
In order to leave comments, you need to log in
Thank you for pushing the idea, the mistake was that one of the books had a category that is not in the database
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question