V
V
Victoria Kabishova2021-08-19 19:00:17
Laravel
Victoria Kabishova, 2021-08-19 19:00:17

How to display data in blade?

The router connects the template: /resources/views/pages/projects.blade.php

@extends('layouts.app')
@section('title', $page->title)
@section('seo_title', $page->seo_title)
@section('seo_description', $page->seo_description)
@section('seo_keywords', $page->seo_keywords)
@if ($page->hasImage('seo_image', 'default'))
  @section('seo_image', app()->make('url')->to($page->image('seo_image', 'default')))
@endif
@section('content')
  <x-projects />
@endsection

The template connects the project class and its template:
/app/View/Components/Projects.php
<?php
namespace App\View\Components;
use App\Models\Project;
use Illuminate\View\Component;
use Illuminate\Database\Eloquent\Collection;
class Projects extends Component
{
    public Collection $projects;
    public array $tags = [];

    public function __construct()
    {
        $this->projects = Project::select('id')->published()->get();
        $this->tags[] = [
            'name' => __('projects.all_projects'),
            'slug' => 'all',
        ];
        foreach ($this->projects as &$project) {
            $tags = $project->tags()->get();
            foreach ($tags as &$tag)
                $this->tags[] = [
                    'name' => $tag->name,
                    'slug' => $tag->slug,
                ];
        }
    }

    public function render()
    {
        return view('components.projects');
    }
}

/resources/views/components/projects.blade.php
<div>
  <h1>{{ Lang::choice('projects.works', 1) }}</h1>
    @if($project ?? '' )
      <x-project id="{{ $project['id'] }}" />
    @endif
</div>

The project template connects the class and template of a specific project:
/app/View/Components/Project.php
<?php
namespace App\View\Components;
use App\Models\Project as ModelsProject;
use Illuminate\View\Component;
class Project extends Component
{
    public function render()
    {
        return view('components.project.solid');
    }
}

/resources/views/components/project/solid.blade.php
@if($project)
<div style="background: {{ $colors[0] }}">
  @if (!is_null($project->url))
    <span>{{ $project->present()->urlHost() }}</span>
  @endif
  @if (!is_null($project->url))
    <a href="{{ $project->url }}" target="_blank" class="stretched-link"></a>
  @endif
</div>
@endif

Some data has already been passed in the templates and their classes, but they are not enough.
It is necessary to get/display the missing information (Name, link, tags, color).
Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
inFureal, 2021-08-19
@Parsifal31017

So what's the problem? You take and take out. I don't understand what the question is.
does the solid.blade.php$project variable come in? I understand that this is some kind of model. Well, just drag through -> the rest of the fields

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question