Laravel - only home route working

試著忘記壹切 提交于 2019-12-24 09:29:33

问题


the problem all routes are typed correctly and checked by php artisan route:list here the output

+--------+----------+------+--------+-------------------------------------------
-------+------------+
|←[32m Domain ←[39m|←[32m Method   ←[39m|←[32m URI  ←[39m|←[32m Name   ←[39m|←[3
2m Action                                           ←[39m|←[32m Middleware ←[39m
|
+--------+----------+------+--------+-------------------------------------------
-------+------------+
|        | GET|HEAD | /    | home   | App\Http\Controllers\QuoteController@getIn
dex    | web        |
|        | POST     | new  | create | App\Http\Controllers\QuoteController@addNe
wQuote | web        |
|        | GET|HEAD | test | test   | App\Http\Controllers\QuoteController@getTe
st     | web        |
+--------+----------+------+--------+-------------------------------------------
-------+------------+

only root route is working nothing else

what I tried:

  • create another route and I made sure that no routes are working only home route, still not working except home
  • tried to change OverrideMode from None to All, didn't fix any
  • tried to type manually localhost/quotes/public/index.php BOOM it works ..

my htaccess file:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

working on:

  • Windows 10

  • XAMP


回答1:


First of all write your form like this

{!! Form::open(array('action' => 'QuoteController@store')) !!}
                <table>
        <tr>
            <td><label for="author-form">Author Name:</label></td>
            <td><input type="text" name="author-form" id="author-form" /></td>
        </tr>
        <tr>
            <td><label for="quote-form">Quote:</label></td>
            <td><textarea name="quote-form" id="quote-form" cols="30" rows="10"></textarea></td>
        </tr>
        <tr>
            <td colspan='2'><button type="submit">Add Quote</button></td>
        </tr>
        <input type="hidden" name="_token" value="{{ Session::token() }}" />
    </table>
                {!!Form::close()!!}

Now for routing part, if you use laravel 5.2 you need to assign web middleware in route like this

Route::group(['middleware' => 'web'], function () {
    Route::resource('quate', 'QuoteController');

});

Finally your QuoteController create store method in it, if you created controller with artisan command it will automatic generate all required methods

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;


class QuoteController extends Controller
{
  public function index(){

        return view('welcome');
    }
    public function create(){
        return view('test');
    }
public function store(Request $request){
       // Some Code here
    }
}

now when you write quate in url it opens welcome view and when you write create it opens the test view and this is working code in my local.



来源:https://stackoverflow.com/questions/37653143/laravel-only-home-route-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!