dongyin2390 2015-12-01 05:07
浏览 115
已采纳

在Laravel内路由? 的.htaccess

I'm currently reading through the documentation and completing this quick-start guide: http://laravel.com/docs/5.1/quickstart#adding-tasks

I'm using Wamp and have installed this Laravel app in "www/laravel/quickstart5/" It works fine to access index through localhost/laravel/quickstart5/public/ When I submit a new task I get redirected to "localhost/task/"

This is my routes.php

<?php


use App\Task;
use Illuminate\Http\Request;

/**
 * Display All Tasks
 */
Route::get('/', function () {
    $tasks = Task::orderBy('created_at', 'asc')->get();

    return view('tasks', [
        'tasks' => $tasks
    ]);
});
/**
 * Add A New Task
 */
Route::post('/task', function (Request $request) {
    $validator = Validator::make($request->all(), [
        'name' => 'required|max:255',
    ]);

    if ($validator->fails()) {
        return redirect('/')
            ->withInput()
            ->withErrors($validator);
    }

    $task = new Task;
    $task->name = $request->name;
    $task->save();

    return redirect('/');

    // Create The Task...
});

/**
 * Delete An Existing Task
 */
Route::delete('/task/{id}', function ($id) {
    Task::findOrFail($id)->delete();

    return redirect('/');
});

I have a file in /app/ called Task.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Task extends Model
{
    //
}

I don't understand how this form is suppose to work. "<form action="/task" method="POST" class="form-horizontal">"

The only thing I get is that I guess I should change the .htaccess in the "/public"-folder

Current .htaccess

<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]

  • 写回答

2条回答 默认 最新

  • dsbruqxgt820011351 2015-12-01 05:33
    关注

    /task will always be relative to the root. You actually have a lot of options to "fix" this - none of which involve editing the .htaccess file.

    1. Use the url helper function. This will generate an absolute URL. In this case, it will be localhost/laravel/quickstart5/public/task.

      action="{{ url('task') }}"
      
    2. If you named your routes, you can use the route helper function instead to generate the absolute URL.

      action="{{ route('task') }}"
      
    3. Run php artisan serve from your favorite CLI. Then, you can access your Laravel project from http://localhost:8000.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 防火墙的混合模式配置
  • ¥15 Ubuntu不小心注销了要怎么恢复啊
  • ¥15 安装powerbuilder10卡在安装程序正在运行这个页面 没有下一步任何指令
  • ¥15 关于mpi的问题:请问遇到这种情况需要怎么解决,出现这个问题后电脑不能进行mpi多核运行只能进行单核运行
  • ¥50 微信聊天记录备份到电脑提示成功了,但还是没同步到电脑微信
  • ¥15 python怎么在已有视频文件后添加新帧
  • ¥20 虚幻UE引擎如何让多个同一个蓝图的NPC执行一样的动画,
  • ¥15 fluent里模拟降膜反应的UDF编写
  • ¥15 MYSQL 多表拼接link
  • ¥15 关于某款2.13寸墨水屏的问题