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('AppModelsProductCategory', 'parent_id', 'id');
}

public function children()
{
return $this->hasMany('AppModelsProductCategory', '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

Related Posts

Codeigniter : Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE) in Laravel project

I’m getting following error: **Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE)** Note : It’s working in local but facing issue in production server. private…

Firebase receive notification while tab is active or on focus

What i want is to be able to perform an action when a user receives a notification while the browser is open and tab is active or…

Laravel’s alias loader does not find class

We have a legacy project that we cannot update and we need to make some changes in symfony’s Response.php in vendor. We have solved this by copying…

Laravel 5 – generic document management

I have a system where you can create different types of unique documents. For instance, one document is called Project Identified and this expects certain inputs. Originally,…

Laravel Nova limit the results in indexQuery

I ran intro a situation where I need to limit the results of a resource to only 3 results. To be more specific, based on the logged…

Auditoria en laravel 5.8 [closed]

Cómo puedo automatizar el registro de actividades de un usuario en laravel? Si un usuario ingresa a un app de laravel, debo guardar toda su actividas, a…

Leave a Reply

Your email address will not be published.