Laravel试图在show.blade.php上获取非对象的属性

时间:2018-08-31 11:13:05

标签: laravel web controller

CompaniesController.php

clb_resultData.CheckedItems.Count 

show.blade.php

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Company;
class CompaniesController extends Controller
 {
 public function index(){ 
    $companies=Company::all();

      return view('Companies.index',['companies'=> $companies]);
}

public function create()
{
    //
}
 public function store(Request $request)
{
    //
}


public function show(Company $company)
    {
     $company=Company::find($company->company_id);
 return view('companies.show',['company'=> $company]);
} 

public function edit(Company $company)
{
    $company=Company::find($company->company_id);
      return view('companies.edit',['company'=> $company]);

   }

  public function update(Request $request, Company $company)
    {    
      $companyUpdate=Company::where('company_id',$company->company_id)->
             update([
            'name'=> $request->input('name'),
            'description'=> $request->input('description')
]);

   if($companyUpdate){
return redirect()->route('companies.show', ['company'=> $company->company_id])
-> with('success','Company updated successfully');
}
     return back()->withInput();

}


public function destroy(Company $company)
{
    $company=Company::find($company->company_id);
  if($company->delete()){
  return redirect()->route('companies.index')->with('success','Company    deleted successfully');
    }

  return back()->withInput()->with('error','Company could not be deleted');
}
 }

web.php

@extends('layouts.app')
 @section('content')<div class="col-md-9 col-lg-9 col-sm-9 pull-right">

   <div class="jumbotron">
    <h1> {{$company->name}}</h1>
    <p class="lead">{{$company->description}}</p>
    <p><a class="btn btn-lg btn-success" href="#" role="button">Get started today</a></p>


  </div>
   {{--  @foreach ($company->projects as $project)
    <h2> {{$project->name}}

    </h2>

    @endforeach --}}  



  <div class="row" style="background:red;margin:10px;">
    <div class="col-lg-4">
      <h2>Safari bug warning!</h2>
      <p class="text-danger">  Information present </p>
      <p><a class="btn btn-primary" href="#" role="button">View details »</a></p>
    </div>

    </div>

  </div>

    <div class="col-sm-3 col-md-3 col-lg-3 pull-left">

      <div class="sidebar-module">
        <h4>Actions</h4>
        <ol class="list-unstyled">
          <li><a href="/companies/{{ $company -> company_id }}/edit">edit</a></li>
          <li>



          <li>


          <a   
          href="#"
              onclick=" var result = confirm('Are you sure you wish to delete this Company?');
                  if( result ){
                          event.preventDefault();
                          document.getElementById('delete-form').submit();
                  }
                      "
                      >
              Delete
          </a>

           <form id="delete-form" action="{{ route('companies.destroy',[$company->company_id]) }}" 
            method="POST" style="display: none;">
                    <input type="hidden" name="_method" value="delete">
                    {{ csrf_field() }}
                    </form>


          </li>
          <li><a href="#">add new</a></li> 
        </ol>
      </div> 
    </div>


@endsection

我正在尝试使用laravel中的这2条路线使用url companies / 12显示页面,显示的错误是

“试图获取非对象的属性(视图:C:\ wamp64 \ www \ pmanager \ pmanager \ resources \ views \ Companies \ show.blade.php)”

当我尝试 路线:: get('/ companies','CompaniesController'); 即使我还没有为演出分配路线,一切都可以正常工作。有人可以帮我说为什么会发生这种情况吗?

0 个答案:

没有答案