草庐IT

Level1Controller

全部标签

php - 从中间件更改目标 Controller /操作

我有两个资源/test和/blabla。对于/test我已经注册了中间件。在中间件中,基于特定条件,我想将当前调用重定向到服务于/blabla资源的Controller/操作,对用户透明(没有任何额外的客户端请求,没有302状态响应代码等。)。我怎样才能实现它? 最佳答案 看起来您的解决方案可能更适合路由文件。您建议在特定条件下提供不同的路线。所以在你的routes.php文件中:Route::get('test',function(){if($condition){returnApp::make('App\Http\Control

php - Laravel 5.1 auth attempt with extra parameters using default auth controller and middleware

如何使用默认身份验证Controller和中间件使用额外参数覆盖Laravel5.1身份验证尝试?假设我有一个状态为=active或inactive的额外字段。我该如何编写该尝试方法? 最佳答案 如documentation中所述您可以传递一个变量数组,它们的键是您要在数据库中验证值的列。$request->get('email'),'password'=>$request->get('password'),'active'=>$request->get('active')]);if($attempt){returnredirect

php - 如何在 PHP 中将多个值从 View 传递到 Controller

我是PHP的新手,我正在尝试将2个整数从我的View传递到我的Controller。我正在使用zend框架2。这是我尝试通过按钮将数据传递到Controller中的操作的方式,但我在操作中收到的值等于0,所以这是错误的,因为我的值不等于0。url('mediador',array('action'=>'associaCorrespondencia','idCompra'=>$Compra[$i]['ID'],'idVenda'=>$Venda[$i]['ID']));?>"method="post">以下是我在操作中接收值的方式:publicfunctionassociaCorresp

php - 如何将参数传递给 Laravel 包中的 Controller 操作?

在我制作的Laravel包中,我想将用户重定向到需要参数的Controller操作(在同一包中)。Controller:publicfunctionpostMatchItem(Request$request,$id){$this->validate($request,['item_match'=>'required|numeric|exists:item,id',]);$spot_buy_item=SpotBuyItem::find($id);$item=Item::find($request->input('item_match'));$price=$item->getPrice()

php - 我们可以在 controller laravel 中使用 helper 吗?

我是laravel的新手,我在Cakephp方面有很好的经验。在Cakephp中,我们仅对View使用帮助程序但我已经在laravel中看到了我退出的代码,我们也在Controller中使用了帮助程序。在controller中使用helper好不好?如果是,那么请告诉我,在Controller中使用助手有什么缺点或优点?请建议我... 最佳答案 如果您谈论的是全局Laravelhelpers,那么是的,您可以在应用程序的任何地方使用它们(Controller、模型、View、中间件、routes.php等),因为它们是全局助手。您还

php - 如何在不使用 ZF2.. 中的任何 Controller 对象的情况下访问 module.php 中的 Controller 插件?

我想在module.php中添加错误处理以在flashmessenger中添加所有错误消息并重定向到特定页面(在我的要求中):publicfunctionhandleError(MvcEvent$e){$exception=$e->getParam('exception');$controller=$e->getTarget();//echo$exception->getMessage();exit;if(!$e->getApplication()->getServiceManager()->get('AuthService')->hasIdentity()){$controller-

php - Laravel 后 Controller 方法和 PostController 不工作

我的Laravel博客项目postcontroller的get方法可以工作,但post方法不工作。我重定向Post方法。但是根据我的代码,它应该返回到我的管理页面。我的Controller代码是validate($request,['title'=>'required|max:120|unique:posts','author'=>'required|max:80','body'=>'required']);$post=newPost();$post->title=$request['title'];$post->author=$request['author'];$post->bod

php - Laravel Controller 获取限制数量的项目

在我的Controller中$items=Item::all();我只想得到前6个项目如何更改代码? 最佳答案 使用take()方法:$items=Item::take(6)->get(); 关于php-LaravelController获取限制数量的项目,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/38930388/

php - 在 Laravel 5.1 中找不到 "Class ' app\Http\Controllers\Controller'

我是Laravel的新手,在学习教程时遇到此错误。这是我在“testController.php”中的代码。这是我的“routes.php”。'test','uses'=>'testController@getHome',]);Route::get('about',['as'=>'about','uses'=>'testController@getAbout',]);我收到这个错误:Class'app\Http\Controllers\Controller'notfound我该如何修复这个错误? 最佳答案 让我们一步一步来。1。检查

php - 如何在 Controller laravel 中使用获取对象

我在Controller中有一个函数可以删除类别及其图像文件。但我无法访问路径属性。我收到此错误未定义属性:Illuminate\Database\Eloquent\Collection::$path。它正在返回路径,但我无法使用它。publicfunctionremove($id){//$category=Category::find($id)->delete();$category_image=CategoryImage::where('category_id','=',$id)->get(['path']);echo$category_image->path;//returnba