Пустой стол во время постера Laravel 5.8 - PullRequest
0 голосов
/ 06 июня 2019

Некоторые части моих взглядов пусты. Заинтересованные стороны - это стороны, в которых информация о внешнем ключе должна быть.

Я разработал приложение, используя Laravel 5.8, и у меня есть контроллер, который обнаруживает различные линии аромата, контроллер для продуктов и контроллер для парфюмерии. Я перенес идентификаторы таблиц «продукты» в таблицу «ароматы». Когда я хочу отобразить информацию о таблице духов на уровне представления, у меня была эта ошибка:

Попытайтесь получить свойство 'name' для безобъекта (Показать: C: \ laragon \ www \ venome \ resources \ views \ admin \ fragrance \ index.blade.php).

Итак, я изменил свой код, но теперь части моего представления пусты.

Маршруты

Route::group(['prefix' => 'admin', 'middleware' => 'auth', 'namespace' => 'admin'], function () {
    Route::get('dashboard', 'DashboardController@index')->name('admin.dashboard');
    Route::resource('ligne', 'LigneController');
    Route::resource('produit', 'ProduitController');
    Route::resource('fragrance', 'FragranceController');
});

Контроллер

namespace App\Http\Controllers\Admin;

use App\Fragrance;
use App\Http\Controllers\Controller;
use App\Ligne;
use App\Produit;

class FragranceController extends Controller
{
    public function index()
    {
        $fragrances = Fragrance::all();
        $lignes = Ligne::all();
        $produits = Produit::all();

        return view('admin.fragrance.index', compact('fragrances', 'lignes', 'produits'));
    }
}

Модель

class Fragrance extends Model
{
    public function lignes()
    {
        return $this->belongsTo(Ligne::class);
    }

    public function produits()
    {
        return $this->belongsTo(Produit::class);
    }
}

class Ligne extends Model
{
    public function fragrances()
    {
        return $this->hasMany(Fragrance::class);
    }
}


class Produit extends Model
{
    public function fragrance()
    {
        return $this->hasMany(Fragrance::class);
    }
}

// просмотр аромата

@extends('layouts.auth')

@section('title','Fragrance')

@push('css')
@endpush

@section('content')
    <div class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-12">
                    <a href="{{ route('fragrance.create') }}" class="btn btn-primary">create</a>
                    @include('layouts.partial.message')
                    <div class="card">
                        <div class="card-header" data-background-color="purple">
                            <h4 class="title">Fragrance</h4>
                        </div>
                        <div class="card-content table-responsive">
                            <table id="table" class="table hover"  cellspacing="0" width="100%">
                                <thead class="text-primary">
                                <th>ID</th>
                                <th>Ligne </th>
                                <th>Produit </th>
                                <th>Nom</th>
                                <th>Description</th>
                                <th>image</th>
                                <th>Créer le</th>
                                <th>Derniére Mis à Jour</th>
                                <th>Action</th>
                                </thead>
                                <tbody>
                                @foreach($fragrances as $key=>$fragrance)
                                    <tr>
                                        <td>{{ $key + 1 }}</td>
                                        <td>{{ $fragrance->ligne->name }}</td>
                                        <td>{{ $fragrance->produit->title }}</td>
                                        <td>{{ $fragrance->name }}</td>
                                        <td>{{ $fragrance->description }}</td>
                                        <td><img class="img-responsive img-thumbnail" src="{{ asset('uploads/fragrance/'.$fragrance->image) }}" style="height: 100px; width: 100px" alt=""></td>
                                        <td>{{ $fragrance->created_at }}</td>
                                        <td>{{ $fragrance->updated_at }}</td>
                                        <td>
                                            <a href="{{ route('fragrance.edit',$fragrance->id) }}" class="btn btn-primary">Edit</a>

                                            <form id="delete-form-{{ $fragrance->id }}" action="{{ route('fragrance.destroy',$fragrance->id) }}" style="display: none;" method="POST">
                                                @csrf
                                                @method('DELETE')
                                            </form>
                                            <button type="button"  class="btn btn-danger" onclick="if(confirm('voulez-vous vraiment suppimer?')){
                                                event.preventDefault();
                                                document.getElementById('delete-form-{{ $fragrance->id }}').submit();
                                                }else {
                                                event.preventDefault();
                                                }"><i class="material-icons">delete</i></button>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

// второй взгляд, который дает пустые таблицы

@extends('layouts.auth')

@section('title','Fragrance')

@push('css')
@endpush

@section('content')
    <div class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-12">
                    <a href="{{ route('fragrance.create') }}" class="btn btn-primary">create</a>
                    @include('layouts.partial.message')
                    <div class="card">
                        <div class="card-header" data-background-color="purple">
                            <h4 class="title">Fragrance</h4>
                        </div>
                        <div class="card-content table-responsive">
                            <table id="table" class="table hover"  cellspacing="0" width="100%">
                                <thead class="text-primary">
                                <th>ID</th>
                                <th>Ligne </th>
                                <th>Produit </th>
                                <th>Nom</th>
                                <th>Description</th>
                                <th>image</th>
                                <th>Créer le</th>
                                <th>Derniére Mis à Jour</th>
                                <th>Action</th>
                                </thead>
                                <tbody>
                                @foreach($fragrances as $key=>$fragrance)
                                    <tr>
                                        <td>{{ $key + 1 }}</td>
                                        <td>
                                            @if(!empty($fragrance->ligne)) {{ $fragrance->ligne->name }} @endif
                                        </td>
                                        <td>
                                            @if(!empty($fragrance->produit)) {{ $fragrance->produit->title }} @endif
                                        </td>
                                        <td>{{ $fragrance->name }}</td>
                                        <td>{{ $fragrance->description }}</td>
                                        <td><img class="img-responsive img-thumbnail" src="{{ asset('uploads/fragrance/'.$fragrance->image) }}" style="height: 100px; width: 100px" alt=""></td>
                                        <td>{{ $fragrance->created_at }}</td>
                                        <td>{{ $fragrance->updated_at }}</td>
                                        <td>
                                            <a href="{{ route('fragrance.edit',$fragrance->id) }}" class="btn btn-primary">Edit</a>

                                            <form id="delete-form-{{ $fragrance->id }}" action="{{ route('fragrance.destroy',$fragrance->id) }}" style="display: none;" method="POST">
                                                @csrf
                                                @method('DELETE')
                                            </form>
                                            <button type="button"  class="btn btn-danger" onclick="if(confirm('voulez-vous vraiment suppimer?')){
                                                event.preventDefault();
                                                document.getElementById('delete-form-{{ $fragrance->id }}').submit();
                                                }else {
                                                event.preventDefault();
                                                }"><i class="material-icons">delete</i></button>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@push('scripts')
@endpush

Я бы хотел, чтобы вся информация отображалась

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...