我想在我的Laravel 4软件包中安装控制器,但我无法使路由工作.
我已经按照Laravel 4文档中的包说明进行操作,并将routes.php文件与非控制器路由一起使用.
有人可以给我一些关于如何让包控制器在Laravel 4中工作的说明,非常感谢.
提前致谢.
拉尔斯
// EDIT:
// routes.php
Route::get('admin', 'Package::AdminController@index'); // Does not work
Route::get('admin', function(){ // Works fine
return 'Dashboard';
})
Run Code Online (Sandbox Code Playgroud) 我正在使用Laravel 4,我有一个显示帖子的页面,例如example.com/posts/1显示了db的第一篇帖子.
如果有人试图转到不存在的网址,我想要做的是将网页重定向到索引.
例如,如果没有第6号帖子,那么example.com/posts/6应该重定向到example.com/posts
这就是我所拥有的,它是否在轨道上?
public function show($id)
{
$post = $this->post->findOrFail($id);
if($post != NULL)
{
return View::make('posts.show', compact('post'));
}
else
{
return Redirect::route('posts.index');
}
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢 :)
我正在构建一个Laravel 4应用程序,我想保护我的管理区域,因此只有用户登录/验证后才能访问它.
做这个的最好方式是什么?
Laravel文档说你可以保护这样的路线:
Route::get('profile', array('before' => 'auth', function()
{
// Only authenticated users may enter...
}));
Run Code Online (Sandbox Code Playgroud)
但是当我的路线看起来像这样时会发生什么:
Route::resource('cms', 'PostsController');
Run Code Online (Sandbox Code Playgroud)
如何保护指向控制器的路由?
提前致谢!
我是Laravel 4的新手.我有一个页面,其中有3个标签(基本上是大的可点击的div)来加载不同的用户信息.我想做的是,我希望能够点击这些选项卡,发出jquery ajax请求,带回局部视图并使用该局部视图更新页面的一部分.我希望能够为每个标签做到这一点.
我点击了事件.我也尝试了不同的代码来完成ajax请求.出于某种原因,没有任何反应.我不知道我是否遗漏了route.php中的内容.有人可以给我一些关于如何做的代码吗?或者可能是其他一些想法?
我这样做了::
Route.php
Route::post('userInfo','UserController@showInfo');
Run Code Online (Sandbox Code Playgroud)
jqueryAjax:
$("divtoUpdatePartialView").click(function(){
$.ajax({
type: "POST",
url:Not Sure,
data: { id: userId }
}).done(function( msg ) {
alert( msg );
});
}
Run Code Online (Sandbox Code Playgroud)
我也试过使用Base Url,但没有任何反应.我在我的母版页上声明了一个ajax库.你能帮帮我还是给我一些其他想法?
非常感谢您的回答.我试过这种方式,这就是我所拥有的......
Route.php:
Route::get('user_Profile/userInfo', 'UserController@getshow');
Run Code Online (Sandbox Code Playgroud)
ajax:
var userId='1';
$.ajax({
type: "POST",
url: 'user_Profile/userInfo',
data: { id: userId }
}).done(function( msg ) {
alert( "the messageis "+msg );
});
My userController::
public function getshow()
{
return "No ajax";
if (Request::ajax()) {
return "yeahhhh";
$html=View::make('user.userProfile')->nest('partial', 'user.userInfoPartial')- >with('title',$title)->render();
}
}
Run Code Online (Sandbox Code Playgroud)
当我直接访问页面时,我收到"No ajax",但是当我尝试ajax-way时,没有任何反应.你能看到我错过的吗?
再次感谢你的帮助..
我最近开始学习Laravel(PHP MVC框架),我在使用以下方式验证用户时遇到了很多问题:Auth :: attempt($ credentials).
我将把我的代码片段放在下面.在我的mySQL数据库中,我有一个记录,其中包含以下key => values:id => 1,username =>'admin',password =>'admin',created_at => 0000-00-00 00:00:00,updated_at => 0000-00-00 00:00:00
验证器通过,但Auth:尝试总是失败.
如果下面的代码和我的小解释还不够,请告诉我!:-)
routes.php文件:
Route::get('login', 'AuthController@showLogin');
Route::post('login', 'AuthController@postLogin');
Run Code Online (Sandbox Code Playgroud)
AuthController:
public function showLogin(){
if(Auth::check()){
//Redirect to their home page
}
//Not logged in
return View::make('auth/login');
}
public function postLogin(){
$userData = array(
'username' => Input::get('username'),
'password' => Input::get('password')
);
$reqs = array(
'username' => 'Required',
'password' => 'Required'
);
$validator = Validator::make($userData, $reqs);
if($validator->passes() && Auth::attempt($userData)){
return Redirect::to('home');
}
return Redirect::to('login')->withInput(Input::except('password'));
}
Run Code Online (Sandbox Code Playgroud) 在我的注册表单中,我有一个昵称字段,用户可以在其中输入文本以在我的网站上标识自己.在过去,一些用户输入了昵称,其他人可能会觉得这些昵称令人反感.Laravel为表单提供验证功能,但是如何确保表单字段不包含用户可能会觉得冒犯的字词?
我有这样的查询:
$users = DB::table('users')->join('user_roles','users.role_id','=','user_roles.id')->get();
Run Code Online (Sandbox Code Playgroud)
和具有列的表id(users.id)和具有列另一个表id和user_id(user_roles.id&user_roles.user_id),
但问题是..返回的$user->id是user_roles.id代替users.id列...如何修复此问题,以便我得到的不是角色ID而是用户ID而不是...
谢谢!
Laravel 新手并试图找出构建我的应用程序的最佳方式。
它同时具有管理界面和 API(JSON、angularjs 前端)。
我的路线目前看起来像:
Route::group(array('prefix' => 'admin', 'before' => 'auth.admin'), function()
{
Route::any('/', array('as' => 'admin.index', function() {
return View::make('admin.index');
}));
Route::resource('countries.products', 'ProductsController');
Route::resource('countries', 'CountriesController');
Route::resource('orders', 'OrdersController');
});
// Route group for API versioning
Route::group(array('prefix' => 'api/v1'), function()
{
Route::resource('products', 'APIProductsController', array('only' => array('index', 'show')));
Route::resource('orders', 'APIOrdersController', array('only' => array('store', 'update')));
});
Run Code Online (Sandbox Code Playgroud)
例如,OrdersController 和 APIOrdersController 中有很多重复的逻辑。我应该以某种方式重新使用单个控制器,也许是内容协商?还是修改 OrdersController 来查询 API 路由而不是使用 eloquent 更好?
还是有另一种更好的方法?
我正在使用新的whereHas方法在Laravel 4.1中为急切加载的关系添加约束.
$broadcast = $broadcast->whereHas('season', function( $query ) use ( $parameterValues ){
$query->where('name', '2011-12' );
});
}
Run Code Online (Sandbox Code Playgroud)
在这个例子中,我正在寻找足球/足球广播,其中的关系是广播belongsTo季节
我想为团队(俱乐部)添加约束,其中关系是广播hasOne家庭俱乐部和广播hasOne离开俱乐部.我想要一个团队(利物浦)是主场或客场俱乐部的结果,所以我尝试使用orWhereHas- L4.1中添加的一个特色
$broadcast = $broadcast->with('homeClub')->whereHas('homeClub', function( $query ) use ( $parameterValues ){
$query->where('abb', $parameterValues['club_abbs'] );
});
$broadcast = $broadcast->with('awayClub')->orWhereHas('awayClub', function( $query ) use ( $parameterValues ){
$query->where('abb', $parameterValues['club_abbs'] );
});
Run Code Online (Sandbox Code Playgroud)
但这似乎取消了我在第一个例子中提到的对赛季的限制.就像通过链接orWhereHas一样,我的where方法"忘记了"他们所约束的东西.
任何帮助,非常感谢 - 谢谢
乔恩.
我有以下RegEx使用和工作:
/\B@(@?\w+(?:::\w+)?)([ \t]*)(\( ( (?>[^()]+) | (?3) )* \))?/x
这个字符串@extends('template', 'test')正确分组并给我我需要的地方.
问题是如果字符串在引号内包含一个未闭合的括号 - 它将失败:
@extends('template', 'te)st')给出@extends('template', 'te)输出
如何告诉此RegEx忽略引号内的括号('或者")
以下是问题的RegExr演示:http://regexr.com/v1?396ci
这是一个应该能够通过的字符串列表:
@extends('template', 'test') // working
@extends('template', $test) // working
@extends('template', 'te()st') // working
@extends('template', 'te)st') // broken
@extends('template', 'te())st') // broken
@extends('template', 'te(st') // broken
@extends('template', 'test)') // broken
@extends('template', '(test') // broken
Run Code Online (Sandbox Code Playgroud)
我把它缩小了 - 我想我需要能够说出来
(
\( <-- only if not inside quotes
(
(?>[^()]+) | (?3)
)*
\) …Run Code Online (Sandbox Code Playgroud)