2016-05-19 32 views
1

這裏是我的控制器代碼:localhost的頁面不laravel工作

<?php 

namespace App\Http\Controllers; 
use Illuminate\Support\Facades\Route; 
use Input; 
use Illuminate\Support\Facades\Redirect; 
use Illuminate\Http\Request; 
use App\Http\Requests; 
use App\models\Designation; 
use Validator; 
class Cdesigination extends Controller 
{ 
    public $flight; 
    public function __construct(){ 
     $this->flight = new Designation; 
    } 
    public function index(request $request) 
    { 
     $this->flight->name = $request->name; 
     $this->flight->detail = $request->detail; 
     $this->flight->token_key = $request->_token; 
     $data=$this->flight->save(); 
     if($data){ 
     return Redirect::to('posts')->withInput()->with('success', 'Inserted Successfully.'); 
     } 
     else { 
     return Redirect::to('posts')->withInput()->with('success', 'Not inserted Successfully.'); 
     } 
    return view('designation'); 
    } 
} 

這裏是航線代碼:

Route::get('/posts', '[email protected]'); 

哪裏是麻煩,如何解決呢?

我認爲重定向關鍵字創造麻煩,因爲當我放棄redirect:: to關鍵字,然後工作正常。

+0

當你說'本地主機不工作'時,你是什麼意思。您的測試頁是否顯示?通過raze你的意思是擦除? –

+0

當我評論這段代碼時,返回Redirect :: away('posts') - > withInput() - > with('success','Inserted Successfully。'); }其他{ return('posts') - > withInput() - > with }工作正常否則顯示本地主機頁面不工作 –

+0

刪除withInput()並嘗試 –

回答

0

看來你要去/posts其中使用[email protected]行動。這個動作總是重定向到同一個頁面。它會一次又一次地重定向到自己。

所以view('designation')將永遠不會被加載:

if ($data) { 
    // If $data is true, redirect 
    return Redirect::to('posts')->withInput()->with('success', 'Inserted Successfully.'); 
} else { 
    // If not, redirect too 
    return Redirect::to('posts')->withInput()->with('success', 'Not inserted Successfully.'); 
} 

// Any code here will never be executed 

我不知道什麼是你要完成的,但如果要加載designation觀點與信息,你應該做這樣的事情:

if ($data) { 
    // If $data is true, redirect 
    return view('designation')->withInput()->with('success', 'Inserted Successfully.'); 
} else { 
    // If not, redirect too 
    return view('designation')->withInput()->with('success', 'Not inserted Successfully.'); 
} 
+0

如何解決這個問題給我任何提示 –

+0

@GhulamAbbas,我不知道你想達到什麼,但我試圖給你一個提示。請檢查更新的答案。 –

0

它不是重定向。您正在使用withInput()with('success', 'Inserted Successfully.')。使用任何一個。您可能想要擦除withInput()並嘗試。你也不會在你的頁面上顯示laravel錯誤嗎?