我有一个资源控制器Items:
Route::resource('items', 'ItemsController');
Run Code Online (Sandbox Code Playgroud)
在ItemsController@store创建新项目的行动中,我需要在使用表单进行操作之前激活CSRF filter(也许Auth filter).但我不能写
$this->beforeFilter('csrf')
Run Code Online (Sandbox Code Playgroud)
它不起作用.当我把这个调用放在父控制器中时,它可以正常工作__construct().
我需要做些什么才能直接为资源控制器操作调用一些过滤器?
如何限制来自Eloquent的返回数据?我试过这个:
$data = Product::all()->take(4)->skip(3);
Run Code Online (Sandbox Code Playgroud)
并返回错误消息: Call to undefined method Illuminate\Database\Eloquent\Collection::skip()
似乎雄辩不支持skip()?那么,我如何抵消和限制数据的雄辩?
谢谢.
我是laravel的新手,我在第一次申请时设置了管理面板授权.我目前设置文件的方式是:
controllers/
admin/
dashboard.php
settings.php
non-admin-controller1.php
non-admin-controller1.php
views/
admin/
dashboard.blade.php
login.blade.php
template.blade.php
non-admin-view1.php
non-admin-view1.php
non-admin-view1.php
Run Code Online (Sandbox Code Playgroud)
......这些是我的路线
Route::get('admin/login', function()
{
return View::make('admin.login');
});
Route::get('admin/logout', function()
{
return Auth::logout();
return Redirect::to('admin/login');
});
Route::post('admin/login', function()
{
$userdata = array('username' => Input::get('username'),
'password' => Input::get('password'));
if (Auth::attempt($userdata))
{
return Redirect::to('admin');
}
else
{
return Redirect::to('admin/login')->with('login_errors',true);
}
});
Route::controller('admin.dashboard');
Route::get('admin', array('before' => 'auth', function() {
return Redirect::to_action('admin@dashboard');
}));
Route::filter('auth', function()
{
if (Auth::guest()) return Redirect::to('admin/login');
});
Run Code Online (Sandbox Code Playgroud)
当我去/ admin时,我被重定向到admin/login并要求登录,这正是我需要它工作的方式.登录后,我被重定向到管理员/仪表板,这一切看起来都很好.然而,我有两个问题.
当我进入管理/注销时,我已经注销,但是用空白页面打招呼(它没有重定向到管理员/登录)
注销后,如果我转到管理员/仪表板,我会收到错误消息
渲染视图出错:[admin.dashboard]
试图获得非对象的属性
我在这做错了什么?我做得对吗?为管理员创建一个单独的包更合理吗?谢谢!
我为迁移创建了一个基类.目前我运行artisan migrate命令,它创建了一个扩展Migrations文件的新迁移,但是我希望包含我的BaseMigration并从那里扩展它.我一直在做这个改变,但我觉得我在不必要地重复自己.
有关如何进行新迁移的任何建议都会自动扩展并加载我的基本迁移?
我使用Slickgrids有很多成功.我有ajax编辑所有工作 - 但我正在尝试添加一个功能;
下面是我的代码,它允许我更新单元格 - 它按预期工作 - 但我希望能够在用json数据返回的值编辑后更改单元格.请参阅下面的代码 - 我已经放入大写字母,我需要一个命令来使用新返回的数据更新已编辑的单元格
grid.onCellChange.subscribe(function(e, args) {
var dataString = "col="+grid.getColumns()[args.cell].name+"&row="+args.item.new_training_calendar_id+"&value="+data[args.row][grid.getColumns()[args.cell].field];
$.ajax({
type: "POST",
url: "mydomain/update_cell",
data: dataString, dataType: "json",
success: function(a) {
if(a.status != "ok") {
alert(a.msg);
undo();
} else {
alert(a.msg);
**CHANGE_CELL_HERE TO (a.newdata);**
}
return false;
} }); });
Run Code Online (Sandbox Code Playgroud) 从Eloquent模型中获取所有行时:
$pin = Pin::all();
Run Code Online (Sandbox Code Playgroud)
我得到一个看起来像这样的数组:
array(2) {
[0]=>
object(Pin)#36 (5) {
["attributes"]=>
array(9) {
["id"]=>
string(1) "2"
["creator"]=>
string(1) "1"
["original"]=>
array(9) {
["id"]=>
string(1) "2"
["creator"]=>
string(1) "1"
}
["relationships"]=>
array(0) {
}
["exists"]=>
bool(true)
["includes"]=>
array(0) {
}
}
}
Run Code Online (Sandbox Code Playgroud)
就像我使用Fluent一样:
$pin = DB::table('pins')->get();
Run Code Online (Sandbox Code Playgroud)
我得到一个没有"属性","原始","现实"指数的普通数组.
我如何使用Eloquent以便返回像FLuent那样的Plain Array?
我按照本教程:http://fideloper.com/post/41750468389/laravel-4-uber-quick-start-with-auth-guide?utm_source=nettuts&utm_medium=article&utm_content=api&utm_campaign=guest_author
本教程:http://laravelbook.com/laravel-database-seeding/
但是,当我尝试跑步时php artisan db:seed,没有任何反应.
我试试这个:
<?php
// app/database/seeds/groups.php
return array(
'table' => 'groups',
array(
'name' => 'Administrador',
'description' => '<p>Permissão total no sistema</p>',
'created_at' => new DateTime,
'updated_at' => new DateTime
),
array(
'name' => 'Moderadores',
'description' => '<p>Podem apenas postar e moderar comentários</p>',
'created_at' => new DateTime,
'updated_at' => new DateTime
)
);
Run Code Online (Sandbox Code Playgroud)
接下来:php artisan db:seed.
php artisan db:seed --env=local
Database seeded!
Run Code Online (Sandbox Code Playgroud)
但:
mysql> select * from groups; …Run Code Online (Sandbox Code Playgroud) 我想使用Angularjs从URL中删除#hash $locationProvider.html5Mode(true).
示例:显示地址栏http://localhost/shop而不是http://localhost/#/shop.
一切都运作良好,直到刷新页面.如果我刷新,则会加入以下Laravel路由(在routes.php中定义)
Route::resource('shop', 'ShoppingController')
Run Code Online (Sandbox Code Playgroud)
不是AngularJS路线(在app.js中定义)
$routeProvider.when('/shop', {
templateUrl: 'templates/shop.html',
controller: 'ShoppingController'
});
Run Code Online (Sandbox Code Playgroud)
我的代码:
routes.php(Laravel Routes)
Route::get('/', function() {
return View::make('index');
});
Route::resource('shop', 'ShoppingController');
Run Code Online (Sandbox Code Playgroud)
app.js(AngularJS路线)
var app = angular.module('shoppingApp',['ngRoute','SharedServices']);
app.config(function($routeProvider, $locationProvider) {
$routeProvider.when('/shop', {
templateUrl: 'templates/shop.html',
controller: 'ShoppingController'
});
$routeProvider.otherwise({ redirectTo: '/' });
$locationProvider.html5Mode(true);
});
Run Code Online (Sandbox Code Playgroud)
我的目录结构:
Project
/app
/...
/views
-index.php (single page application file)
-routes.php (Laravel routes)
/public
/...
/js
-angular.js
-app.js
-index.php (Laravel index file)
Run Code Online (Sandbox Code Playgroud)
尝试的解决方案:
重写htaccess文件,以便将所有请求重定向到index.php(单页应用程序文件,AngularJS将从该文件中接管路由).问题:通过这种方式,Laravel路由(Route :: resource('shop','ShoppingController'); - 与数据库交互所必需的)变得无法访问AngularJS $ …
有人可以解释一下Laravel中RESTful控制器和资源控制器之间的区别吗?我也有一些问题 -
什么时候我应该使用RESTful控制器和资源控制器?
RESTful控制器和资源控制器是否有任何Controller操作的命名约定?
如果我使用RESTful控制器,我如何为控制器定义路由?
对于构建控制器方法最好的API?
继学习Laravel 4应用程序开发 - Hardik Danger之后.
我尝试通过执行以下操作来创建我的第一个带有工匠的控制器:
php artisan Usercontroller:make users
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
[InvalidArgumentException]
There are no commands defined in the "Usercontroller" namespace.
Did you mean this?
controller
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?