Displaying breadcrumbs in Laravel

I am beginner in Laravel. I use in my project Laravel 6. I have this migration:

public function up()
{
Schema::create('product_categories', function (Blueprint $table) {
$table->bigIncrements('id');
$table->char('enable', 1)->default(0);
$table->string('name', 85)->nullable();
$table->string('url_address', 160);
$table->integer('level')->default(0);
$table->unsignedBigInteger('parent_id')->nullable();
$table->foreign('parent_id')->references('id')->on('product_categories')->onDelete('cascade');
$table->bigInteger('number')->default(0);
$table->engine = "InnoDB";
$table->charset = 'utf8mb4';
$table->collation = 'utf8mb4_unicode_ci';
});
}

In controller I Have this code:

$categories = $this->model->listWithPaginateProductCategories($this->sortBy['orderByColumn'] ?? 'number', $this->sortBy['orderBy'] ?? 'asc', [], ['*']);

return view('category_list', ['categories' => $categories]);

And my Repository:

public function listWithPaginateProductCategories(string $orderByColumn, string $orderBy = 'desc', array $with = [], array $columns = ['*'], int $perPage = 10)
{
return $this->model->with($with)->where('level', 0)
->orderBy($orderByColumn, $orderBy)
->paginate($perPage, $columns)->appends(request()->query());
}

and Model:

class ProductCategory extends Model
{
use ScopeActiveTrait;

protected $guarded = ['id'];
protected $fillable = ['enable', 'name', 'url_address', 'level', 'parent_id', 'number'];
public $timestamps = false;

//protected $table = 'products_category';

public function parent()
{
return $this->belongsTo('App\Models\ProductCategory', 'parent_id', 'id');
}

public function children()
{
return $this->hasMany('App\Models\ProductCategory', 'id', 'parent_id');
}

public function products()
{
return $this->belongsToMany(Product::class, 'product_selected_categories', 'category_id', 'product_id');
}
}

I print my code in view:

@foreach($categories as $value)
<li data-id="" id="">
<tr class="sortItem" data-id=""
id="">
<td class="skin skin-flat"><input value=""
name="id[]"
type="checkbox"
class="icheckbox_square-red ">
</td>

<td><i class="la la-arrows"></i>
<a href=""
class="text-bold-600 "></a>
<p class="text-muted"></p>
</td>

<td>

@if ($value->enable == 1) <span
class="badge badge-success badge-md "><i
class="ft-thumbs-up"></i> Aktywny </span> @else
<span class="badge badge-danger badge-md"><i
class="ft-thumbs-down"></i> Nieaktywny </span>
@endif

</td>


<td>
<a href=""
class="badge badge-info badge-md "><i
class="ft-aperture"></i> Edytuj</a>
<a href=""
class="badge badge-secondary badge-md "><i
class="ft-aperture"></i> Rozwiń</a>
</td>

</tr>
</li>
@endforeach

<div class="mx-auto"></div>

I don't need pagination. We can remove it.

I need to display on the breadcrumbs page. So the current category and subcategory in which the user is located. There can be an unlimited number of categories and subcategories.

How can I make it?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3dmkrBs
via IFTTT

تعليقات

المشاركات الشائعة من هذه المدونة

I am unable to figure out how to create payment collection request, after a form has been submitted in laravel

laravel, mysql transaction not working after failed one time