搜索按钮错误:尝试获取非对象(视图)的属性'showname'

ugmeyewa  于 2021-07-27  发布在  Java
关注(0)|答案(0)|浏览(251)

我得到这个错误:试图在这一行获取非对象(view:/home/laravel/web/laravel.swt101.eu/public\u html/abonamenty/resources/views/proforms/index.blade.php)的属性'showname'

<td>{{ $proform->user->showname }}</td>

单击“我的视图”中的“搜索”按钮后。代码中的搜索按钮位于我的视图的开头:

@extends('layouts.app')

@section('content')
    <div class="row">
        <div class="col-lg-12 margin-tb">
            <div class="pull-left">
                <h2>Zarządzanie proformami</h2>
            </div>

 <div class="col-md-4">
<form action="/search3" method="get">
<div class="input-group">
<input type="search" name="search" class="form-control">
<span class="input-group-prepend">
<button type="submit" class="btn btn-primary">Wyszukaj</button>
</span>
</div>
</form>
</div>           

            <div class="pull-right">
                @can('product-create')
                <a class="btn btn-success" href="{{ route('proforms.create') }}"> Utwórz nową proformę</a>
                @endcan
            </div>
        </div>
    </div>

    @if ($message = Session::get('success'))
        <div class="alert alert-success">
            <p>{{ $message }}</p>
        </div>
    @endif

    <table class="table table-bordered">
        <tr>

            <th scope="col">@sortablelink('id', 'Numer')</th>
            <th scope="col">@sortablelink('proformnumber', 'Numer proformy')</th>
            <th scope="col">@sortablelink('user_id', 'Kontrachent')</th>
            <th scope="col">@sortablelink('proformdate', 'Data wystawienia')</th>
            <th scope="col">@sortablelink('selldate', 'Data sprzedaży')</th>
            <th scope="col">@sortablelink('paymentdate', 'Termin płatności')</th> 
            <th scope="col">@sortablelink('status', 'Status')</th> 
            <th scope="col">@sortablelink('nettotal', 'Netto razem')</th>
            <th scope="col">@sortablelink('grosstotal', 'Brutto razem')</th>              
            <th width="280px">Akcja</th>
        </tr>
        @foreach ($proforms as $proform)
        <tr>
            <td>{{ ++$i }}</td>
            <td>{{ $proform->proformnumber }}</td>
            <td>{{ $proform->user->showname }}</td>
            <td>{{ $proform->proformdate }}</td>
            <td>{{ $proform->selldate }}</td>
            <td>{{ $proform->paymentdate }}</td>
            <td>{{ $proform->status }}</td>
            <td>{{ $proform->nettotal }}</td>
            <td>{{ $proform->grosstotal }}</td>

            <td>
                <form action="{{ route('proforms.destroy',$proform->id) }}" method="POST">
                    <a class="btn btn-info" href="{{ route('proforms.show',$proform->id) }}">Więcej</a>
                    @can('product-edit')
                    <a class="btn btn-primary" href="{{ route('proforms.edit',$proform->id) }}">Edytu</a>
                    @endcan

                    @csrf
                    @method('DELETE')
                    @can('product-delete')
                    <button type="submit" class="btn btn-danger">Usuń</button>
                    @endcan
                </form>
            </td>
        </tr>
        @endforeach
    </table>

{!! $proforms ?? ''->appends(request()->except('page'))->render() !!}

<p class="text-center text-primary"><small>ARTplus 2020</small></p>
@endsection

这是我的路线:

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

Route::group(['middleware' => ['auth']], function () {
Route::resource('roles', 'RoleController');
Route::resource('users', 'UserController');
Route::resource('permissions', 'PermissionController');
Route::resource('products', 'ProductController');
Route::resource('invoices', 'InvoiceController');

Route::resource('category', 'CategoryController');
Route::resource('invoices', 'InvoiceController');
Route::resource('proforms', 'ProformController');
Route::get('/search', 'UserController@search');
Route::get('/search2', 'ProductController@search2');
Route::get('/search3', 'ProformController@search3');
Route::get('data', 'UserController@index');
Route::get('posts', 'PostController@index');
Route::get('/prodview', 'TestController@prodfunct');

这是我的控制器中的搜索功能:

public function search3(Request $request)
{
$search = $request->get('search');
$requestData = ['showname'];

$query = User::query();
foreach ($requestData as $field){
$query->orWhere($field, 'like', '%'.$search.'%');
}
$data2=$query->paginate(5);
return view('proforms.index', ['proforms' => $data2])->with('i', ($request->input('page', 1) - 1) * 5);
}

这是我的用户模型:

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;
use Kyslik\ColumnSortable\Sortable;
use Illuminate\Database\Eloquent\Model;

class User extends Authenticatable
{
    use Notifiable;
    use HasRoles;
    use Sortable;
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password', 'surname', 'showname', 'business', 'NIP', 'PESEL', 'address', 'city', 'postalcode', 'phone', 'comments', 
    ];
    public $primaryKey = 'id';
    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    public $sortable = ['name',
                        'email',
                         'surname', 
                        'showname', 
                        'business',
                        'address',
                        'city',
                        'phone',
                        'role',
                       ];

        public function products()
    {
        return $this->hasMany('App\Product');
    }
        public function invoices()
    {
        return $this->hasMany('App\Invoice');
    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题