关键词:
【中文标题】无法访问 Laravel 路由中的 URL【英文标题】:Can't access URL in Laravel routes 【发布时间】:2014-11-25 19:55:45 【问题描述】:我现在正在学习 Laravel,我通过创建一个简单的 CRUD(CREATE-READ-UPDATE-DELETE)来做到这一点。这是我学习新框架的方式。在我使用 CodeIgniter 之前,我发现 Laravel 比 CodeIgniter 好得多,它有很多功能。
我正在学习本教程
http://www.allshorevirtualstaffing.com/developing-crud-applications-in-laravel-4/
我正在显示 CREATE 视图。但我无法访问它的路线。
这是我的文件夹结构
wamp
www
mylaravel
app
bootstrap
public
vendor
到目前为止,我有这些代码:
控制器
<?php
class EmployeesController extends \BaseController
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
$employees = Employee::all();
return View::make('index', compact('employees'));
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
return View::make('create');
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
//
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
//
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
//
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
//
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
//
public function handleCreate()
$employee = new Employee;
$employee->first_name = Input::get('first_name');
$employee->last_name = Input::get('last_name');
$employee->email = Input::get('email');
$employee->save();
return Redirect::action('EmployeesController@index');
型号
<?php
class Employee extends Eloquent
?>
查看(index.blade.php)
@extends('layout')
@section('content')
<div class="page-header" style="border: 1x solid #0077b3; text-align-center">
<h1>EMS <small> Better Employee Management </small> </h1>
</p></div>
<div class="panel panel-default">
<div class="panel-body">
<a href=" action('EmployeesController@create') " class="btn btn-info">Add new employee</a>
</div>
@if ($employees->isEmpty())
There are no employees! :(
@else
<table class="table table-striped">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($employees as $employee)
<tr>
<td> $employee->first_name </td>
<td> $employee->last_name </td>
<td> $employee->email </td>
<td>
<a href=" action('EmployeesController@edit', $employee->id) " class="btn btn-default">Edit</a>
<a href=" action('EmployeesController@delete', $employee->id) " class="btn btn-danger">Delete</a>
</td>
</tr>
@endforeach
</tbody>
</table>
@endif
@stop
</div>
</div>
查看(layout.blade.php)
<!DOCTYPE html>
<html>
<head>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
<style type="text/css">
table form margin-bottom: 0;
form ul margin-left: 0; list-style: none;
.error color: red; font-style: italic;
body padding-top: 20px;
</style>
</head>
<body>
<div class="container">
@if (Session::has('message'))
<div class="flash alert">
<p> Session::get('message') </p>
</div>
@endif
@yield('content')
</div>
</body>
</html>
查看(create.blade.php)
@extends('layout')
@section('content')
<div class="page-header" style="border: 1px solid #0077b3;">
<h1>Add New Employee</h1>
@if( $errors->count() > 0 )
<div class="alert alert-danger">
<ul>
@foreach( $errors->all() as $message)</p>
<li> $message </li>
@endforeach
</ul>
</div>
@endif
<form action=" action('EmployeesController@handleCreate') " method="post" role="form">
<div class="form-group">
<label for="first_name">First Name</label>
<input type="text" class="form-control" name="first_name" />
</div>
<div class="form-group">
<label for="last_name">Last Name</label>
<input type="text" class="form-control" name="last_name" />
</div>
<div class="form-group">
<label for="email">Last Name</label>
<input type="text" class="form-control" name="email" />
</div>
<input type="submit" value="Add" class="btn btn-primary" />
<a href=" action('EmployeesController@index') " class="btn btn-link">Cancel</a>
</form>
@stop
</div>
路线(routes.php)
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
/*
Route::get('/', function()
return View::make('hello');
);
*/
Route::model('employee', 'Employee');
Route::get('/', 'EmployeesController@index');
Route::get('/create', 'EmployeesController@create');
Route::get('/edit/$employee', 'EmployeesController@edit');
Route::get('/delete/$employee', 'EmployeesController@delete');
Route::post('/create', 'EmployeesController@handleCreate');
Route::post('/edit', 'EmployeesController@handleEdit');
Route::post('/delete', 'EmployeesController@handleDelete');
当我访问这个 URL 时:
http://localhost/mylaravel/public/
它显示带有员工表的索引页面
但是当我点击添加新员工时
转到这个页面
http://localhost/mylaravel/public/create
我有这个错误:
Not Found
The requested URL /mylaravel/public/create was not found on this server.
Apache/2.4.9 (Win64) OpenSSL/1.0.1g PHP/5.5.12 Server at localhost Port 80
我不知道我哪里出错了。你能帮我解决这个问题吗?
【问题讨论】:
检查mod_rewrite
是否启用 - sudo a2enmod rewrite
。还有you can just create a Resource Controller to handle all your CRUD
【参考方案1】:
您需要在 Apache 配置文件中启用 mod_rewrite - 在 httpd.conf
行中:
LoadModule rewrite_module modules/mod_rewrite.so
开头应该没有#
。更改后,您应该重新启动服务器。
您还需要在 public
目录中拥有来自 Laravel 的默认 .htaccess
文件 - 我提到它是因为在网络服务器上有时 .htaccess
文件是隐藏的,如果您从 FTP 复制项目,您可能不会复制它们。
【讨论】:
这里的首选方法是将/public
添加到VirtualHost 中的DocumentRoot
路径中。
哇,它好用,谢谢.. :) 这对我的学习真的有很大帮助.. :)访问 Vue 模板中的所有 Laravel 路由
】访问Vue模板中的所有Laravel路由【英文标题】:AccessallLaravelroutesinVuetemplate【发布时间】:2021-02-0802:35:41【问题描述】:我基本上是在尝试使用Laravel中的Vue创建某种动态表。我已成功创建表并通过jquery的$.getJSON方法获取数据。... 查看详情
如何忽略 Laravel 路由中的站点地图 url?
】如何忽略Laravel路由中的站点地图url?【英文标题】:HowtoignoresitemapurlfromLaravelrouting?【发布时间】:2017-09-0815:49:11【问题描述】:我在http://example.com的根目录下有sitemap.xml当我尝试访问http://example.com/sitemap.xml时。它显然会抛出... 查看详情
Laravel 无法访问除根以外的其他路由(使用 XAMPP)
】Laravel无法访问除根以外的其他路由(使用XAMPP)【英文标题】:LaravelCan\'tAccessotherRoutesbuttheRoot(withXAMPP)【发布时间】:2019-05-0715:30:24【问题描述】:我刚刚开始使用Laravel(v5.7),我正在尝试将其设置为在虚拟主机中工作(我正... 查看详情
只能访问 Laravel 5.2 中的 / 路由
】只能访问Laravel5.2中的/路由【英文标题】:abletoaccessonlythe/routeinLaravel5.2【发布时间】:2018-01-0109:47:34【问题描述】:我只能访问“/”路线,而我所有其他路线都返回404。我在一个新的EC2实例上安装了laravel,并确保我的php、Mysq... 查看详情
Blade 中的 laravel 7 路由/url 参数
】Blade中的laravel7路由/url参数【英文标题】:laravel7route/urlparaminBlade【发布时间】:2021-01-0913:24:10【问题描述】:我尝试通过GET请求将参数type=Business传递给注册表格。在Welcome.blade中我有两个指向RegisterForm的链接。@if(Route::has(\'regi... 查看详情
laravel路由无法访问,报404,noqueryresultsformodel[appmodels...]
今天遇到了一个问题,在routes/web.php中配置了路由,但始终无法访问该路由,一直报404。Route::resource(‘gift_packs‘,‘GiftPacksController‘,[‘only‘=>[‘index‘,‘show‘,‘create‘,‘store‘,‘update‘,‘edit‘,‘destroy‘]]);Route::get(‘gift_... 查看详情
为啥 Laravel 中的 PHPUnit 不能访问存在的路由?
】为啥Laravel中的PHPUnit不能访问存在的路由?【英文标题】:Whycan\'tPHPUnitinLaravelaccessaroutethatexists?为什么Laravel中的PHPUnit不能访问存在的路由?【发布时间】:2016-06-1602:59:37【问题描述】:我在运行PHPUnit测试时遇到了问题,但在... 查看详情
PhpUnit 无法访问外部 url
...t/testsite/testpage.html)现在在同一台机器上,我运行了一个laravel5.2实例,其中有一个名为testroute的命名路由。我 查看详情
在 Laravel 5.1 中使用 Blade 访问嵌套 URL
】在Laravel5.1中使用Blade访问嵌套URL【英文标题】:AccessingNestedURLUsingBladeinLaravel5.1【发布时间】:2016-05-2011:46:00【问题描述】:我正在尝试使用Laravel5.1中的嵌套url访问页面,但我已经走到了死胡同。我想在url中间使用参数发出GET... 查看详情
Laravel - 使用惯性访问路由来填充 Vuejs3 中的道具
】Laravel-使用惯性访问路由来填充Vuejs3中的道具【英文标题】:Laravel-RoutingwithInertiaVisittofillpropinVuejs3【发布时间】:2021-11-1101:34:15【问题描述】:我想在Laravel路由中不使用控制器将数据从pageA发送到pageB。(Laravel/VueJS3/InertiaJS)在... 查看详情
无法通过 url http://localhost/myproject/public/ 访问 laravel 项目
】无法通过urlhttp://localhost/myproject/public/访问laravel项目【英文标题】:Cannotaccesslaravelprojectviaurlhttp://localhost/myproject/public/【发布时间】:2018-06-2705:09:26【问题描述】:当我运行phpartisanserve然后复制这个URLhttp://127.0.0.1:8000/。其作品... 查看详情
如何在 Laravel 5 中访问刀片中的 URL 段?
】如何在Laravel5中访问刀片中的URL段?【英文标题】:HowtoaccessURLsegment(s)inbladeinLaravel5?【发布时间】:2015-10-2805:56:25【问题描述】:我有一个网址:http://localhost:8888/projects/oop/2我要访问第一段-->projects我试过了<?phpecho$segmen... 查看详情
Laravel 中的返回视图未显示正确的 URL
】Laravel中的返回视图未显示正确的URL【英文标题】:ReturnViewinLaravelnotdisplayingproperURL【发布时间】:2014-10-2204:52:52【问题描述】:我现在正在通过使用资源路由进行路由这是我在路由器中的代码,Route::resource(\'item-sales\',\'ItemSales... 查看详情
配置完所有内容后无法通过域 URL 访问我的 Laravel 应用程序
】配置完所有内容后无法通过域URL访问我的Laravel应用程序【英文标题】:Can\'taccessmyLaravelapplicationthroughdomainURLafterconfiguringeverything【发布时间】:2019-04-0207:25:20【问题描述】:我正在寻找有关我的laravel应用程序可能出现的问题/... 查看详情
尝试使用 XAMPP 访问虚拟主机上的 Laravel 项目时无法检索请求的 URL
】尝试使用XAMPP访问虚拟主机上的Laravel项目时无法检索请求的URL【英文标题】:TherequestedURLcouldnotberetrievedwhiletryingtoaccessLaravelprojectonVirtualHostwithXAMPP【发布时间】:2021-09-2719:28:23【问题描述】:我想用XAMPP为我的Laravel项目创建一... 查看详情
无法从控制器 laravel 访问视图中的变量
】无法从控制器laravel访问视图中的变量【英文标题】:can\'taccessvariableinviewfromcontrollerlaravel【发布时间】:2018-12-2716:44:37【问题描述】:我无法在函数show()中访问$prospectus,但在laravel版本5.6.27中的函数store()中运行良好publicfunction... 查看详情
Laravel 前缀路由和 json 文件 url 不匹配
】Laravel前缀路由和json文件url不匹配【英文标题】:Laravelprefixrouteandjsonfileurlisnotmatching【发布时间】:2020-04-2107:57:01【问题描述】:我正在尝试Laravel6前缀。我的问题是当我从我的主页http://localhost:8000/访问我的侧边栏http://localhost... 查看详情
Laravel 5:仅在一个 URL 上路由 CORS 问题
】Laravel5:仅在一个URL上路由CORS问题【英文标题】:Laravel5:routingCORSissueonjustoneURL【发布时间】:2020-01-0812:23:43【问题描述】:我正在尝试向外部laravel站点发出2个ajax请求。其中一个请求完美运行(“列表”)。另一个(“savedevi... 查看详情