2017-03-03 72 views
0

我有兩個安裝laravel一個本地和另一個覆盆子pi。我正在使用git存儲庫進行同步。在葉片剎車視圖中調用模型功能 - Laravel

除了一件事情之外,一切都很好:我有一對多的師生關係。

這是我的老師型號:

教師 - 型號

<?php 

namespace App; 

use Illuminate\Notifications\Notifiable; 
use Illuminate\Foundation\Auth\User as Authenticatable; 

class Teacher extends Authenticatable 
{ 
    use Notifiable; 

    protected $guard = 'teacher'; 

    /** 
    * The attributes that are mass assignable. 
    * 
    * @var array 
    */ 
    protected $fillable = [ 
     'name', 'email', 'password', 
    ]; 

    /** 
    * The attributes that should be hidden for arrays. 
    * 
    * @var array 
    */ 
    protected $hidden = [ 
     'password', 'remember_token', 
    ]; 

    public function students() { 
     return $this->hasMany('App\Student'); 
    } 

    public function school() { 
     return $this->belongsTo('App\School'); 
    } 
} 

這是部分地方網絡版突破

教師 - 查看

@foreach ($teachers as $teacher) 
       <tr> 
       <td>{{ $teacher->id }}</td> 
       <td>{{ $teacher->name }}</td> 
       <td>{{ $teacher->school->name }}</td> 
       <td>{{ $teacher->email }}</td> 
       <td><a class="btn btn-small btn-info" href="teachers/{{ $teacher->id }}">View</a></td> 
       </tr> 
@endforeach 

的TeacherController

<?php 

namespace App\Http\Controllers\Admin; 

use App\Teacher; 
use App\School; 
use Illuminate\Http\Request; 
use App\Http\Requests\StoreTeacher; 
use App\Http\Controllers\Controller; 
use Illuminate\Contracts\Validation\Validator; 

class TeacherController extends Controller 
{ 
    /** 
    * Create a new controller instance. 
    * 
    * @return void 
    */ 
    public function __construct() 
    { 
     $this->middleware('auth:admin', ['except' => 'logout']); 
    } 
    /** 
    * Display a listing of the resource. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function index() 
    { 
     $teachers = Teacher::all(); 
     $schools = School::all(); 
     return view('admin.teachers.index') 
        ->with('teachers', $teachers) 
        ->with('schools', $schools); 
    } 

    /** 
    * Store a newly created resource in storage. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @return \Illuminate\Http\Response 
    */ 
    public function store(StoreTeacher $request) 
    { 
     $teacher = new Teacher; 
     $teacher->name = $request->input('name'); 
     $teacher->email = $request->input('email'); 
     $teacher->password = $request->input('password'); 
     $teacher->school_id = $request->input('school_id'); 

     $teacher->save(); 

     return redirect('admin/teachers')->with('status', 'New teacher created!'); 
    } 

    /** 
    * Display the specified resource. 
    * 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function show($id) 
    { 
     $teacher = Teacher::findOrFail($id); 
     return view('admin.teachers.show')->with('teacher', $teacher); 
    } 

    /** 
    * Show the form for editing the specified resource. 
    * 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function edit($id) 
    { 
     $teacher = Teacher::findOrFail($id); 
     return view('admin.teachers.edit')->with('teacher', $teacher); 
    } 

    /** 
    * Update the specified resource in storage. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function update(Request $request, $id) 
    { 
     // 
    } 

    /** 
    * Remove the specified resource from storage. 
    * 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function destroy($id) 
    { 
     $teacher = Teacher::findOrFail($id); 
     $teacher->delete(); 
     return redirect('/admin/teachers')->with('status', 'Teacher deleted!'); 
    } 
} 

這是錯誤:

in 5bdd62e78cd0ce07d649d6a0703baeeac6c5e20e.php line 21 
at CompilerEngine->handleViewException(object(ErrorException), 1) in PhpEngine.php line 44 
at PhpEngine->evaluatePath('/var/www/The-Film-Corner/storage/framework/views/5bdd62e78cd0ce07d649d6a0703baeeac6c5e20e.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(Illuminate\Support\ViewErrorBag), 'teachers' => object(Collection), 'schools' => object(Collection))) in CompilerEngine.php line 59 
at CompilerEngine->get('/var/www/The-Film-Corner/resources/views/admin/teachers/index.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'teachers' => object(Collection), 'schools' => object(Collection))) in View.php line 137 
at View->getContents() in View.php line 120 
at View->renderContents() in View.php line 85 
at View->render() in Response.php line 38 
at Response->setContent(object(View)) in Response.php line 225 
at Response->__construct(object(View)) in Router.php line 602 
at Router->prepareResponse(object(Request), object(View)) in Router.php line 560 
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 30 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41 
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 148 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Authenticate.php line 43 
at Authenticate->handle(object(Request), object(Closure), 'admin') in Pipeline.php line 148 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 65 
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 148 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49 
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 148 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64 
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 148 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37 
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 148 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59 
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 148 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 102 
at Pipeline->then(object(Closure)) in Router.php line 561 
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 520 
at Router->dispatchToRoute(object(Request)) in Router.php line 498 
at Router->dispatch(object(Request)) in Kernel.php line 174 
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 30 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in TransformsRequest.php line 30 
at TransformsRequest->handle(object(Request), object(Closure)) in Pipeline.php line 148 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in TransformsRequest.php line 30 
at TransformsRequest->handle(object(Request), object(Closure)) in Pipeline.php line 148 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ValidatePostSize.php line 27 
at ValidatePostSize->handle(object(Request), object(Closure)) in Pipeline.php line 148 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46 
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 148 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 102 
at Pipeline->then(object(Closure)) in Kernel.php line 149 
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116 
at Kernel->handle(object(Request)) in index.php line 54 

最不可理解的是,在所有應用程序的本地版本工作正常。

感謝您幫助

+0

有時在渲染的視圖中找到它更容易。在您的存儲文件夾中查找5bdd62e78cd0ce07d649d6a0703baeeac6c5e20e.php(或其引用的任何文件)並在那裏查找第21行。 – aynber

+0

你能提供你的控制器代碼嗎? – nextt1

+0

@aynber這不是那麼容易....行21​​{{$ teacher-> school-> name}} –

回答

0

嘗試用$teacher->school()->name更換$teacher->school->name