如何将硬编码变量传递给控制器?
我的路线是:
Route::group(array('prefix' => $locale), function() {
Route::get('/milk', array('as' => 'milk', 'uses' => 'ProductsController@index'));
});
Run Code Online (Sandbox Code Playgroud)
我想做的事情如下:
Route::get('/milk', array('as' => 'milk', 'uses' => 'ProductsController@index(1)'));
Run Code Online (Sandbox Code Playgroud)
但这不起作用.
如何才能做到这一点?
对不起,如果我没有解释清楚.
我希望简单地硬编码(由我设置)某些路由的type_id,如下所示:
Route::get('/milk', array('as' => 'milk', 'uses' => 'ProductsController@index(1)'));
Route::get('/cheese', array('as' => 'cheese', 'uses' => 'ProductsController@index(2)'));
...
Run Code Online (Sandbox Code Playgroud)
我的产品控制器供参考:
class ProductsController extends BaseController {
public function index($type_id) {
$Products = new Products;
$products = $Products->where('type_id', $type_id)->get();
return View::make('products.products', array('products' => $products));
}
}
Run Code Online (Sandbox Code Playgroud) 我有以下内容:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Imagine\Image\Box;
use Imagine\Image\ImageInterface;
use Imagine;
class UploadController extends Controller {
public function processImage($request) {
$file = $request->file('file');
$path = '/images';
$fileName = 'image.png';
if ($file) {
$file->move('../public' . $path, $fileName);
$gThumb = $this->createThumbnail(219, 300, '../public/images', 'image', 'png', 'thumb', true);
$pThumb = $this->createThumbnail(300, 300, '../public/images', 'image', 'png', 'pthumb');
return response()->json([
'gallery_thumbnail' => $path . '/' . $gThumb,
'upload_thumbnail' => $path . '/' . $pThumb
]);
}
}
function createThumbnail($height, $width, $path, $filename, $extension, $postfix = …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的应用程序提出一个高效灵活的RBAC解决方案.我做了一点研究,并认为我创造了以下内容.
在我的用户模型中,我有:
...
public function role() {
return $this->belongsToMany('App\Models\Role', 'user_roles');
}
public function hasRole($role) {
if($this->role->where('name', $role)->first())
return true;
}
...
Run Code Online (Sandbox Code Playgroud)
以及用法示例:
Route::group(['middleware' => 'auth'], function () {
Route::get('/dashboard', function () {
if (Auth::user()->hasRole('Sales')) {
return view('dashboards/sales');
} else {
return 'Don\'t know where to send you :(';
}
});
});
Run Code Online (Sandbox Code Playgroud)
权限分配给角色,但在上面的示例中未检查权限.然后将角色分配给用户,并且用户可以具有许多角色.
我的工作方式是否可扩展且有效的RBAC解决方案?
我目前正在学习Laravel并发现它非常有用和有趣.
目前我正在制作一份简单的在线申请表.
使用Laravel语法执行操作的最大优点是:
{{ Form::open(array('url' => 'foo/bar')) }}
Run Code Online (Sandbox Code Playgroud)
与简单相反:
<form action="foo/bar">
Run Code Online (Sandbox Code Playgroud)
要么:
echo Form::text('username');
Run Code Online (Sandbox Code Playgroud)
代替:
<input type="text" name="username" />
Run Code Online (Sandbox Code Playgroud)
Laravel方式必须更好,我只想知道为什么?
我正在尝试使用Laravel 5设置Angular.
我试过在appServiceProvider中做:
public function boot()
{
\Blade::setRawTags("[[", "]]");
\Blade::setContentTags('<%', '%>'); // for variables and all things Blade
\Blade::setEscapedContentTags('<%%', '%%>'); // for escaped data
}
Run Code Online (Sandbox Code Playgroud)
附:
<div>
<input type="text" ng-model="yourName" placeholder="Enter a name here">
<h1>Hello, {{ yourName }}!</h1>
</div>
Run Code Online (Sandbox Code Playgroud)
但是我得到了:
Use of undefined constant yourName - assumed 'yourName'...
Run Code Online (Sandbox Code Playgroud) 我是C#的新手.我在Unity中创建了一些东西来帮助我更好地学习C#和Unity.
我想知道原因:
Input.GetKeyDown(KeyCode.UpArrow))
Run Code Online (Sandbox Code Playgroud)
放入内部时仅触发一次:
void Update()
Run Code Online (Sandbox Code Playgroud)
由于更新是一个循环,为什么在按住键的同时不会触发(在我的情况下导致球体移动)?
我已经设法通过使用两个在按下和释放按键时改变的bool来工作.
这是我正在玩的完整脚本,用于移动球体并模拟加速/减速:
using UnityEngine;
using System.Collections;
public class sphereDriver : MonoBehaviour {
int x ;
bool upPressed = false ;
bool downPressed = false ;
void Start()
{
x = 0 ;
}
void Update ()
{
if(x > 0) {
x -= 1 ;
}
if(x < 0) {
x += 1 ;
}
if(Input.GetKeyDown(KeyCode.UpArrow))
{
upPressed = true ;
}
else if(Input.GetKeyUp(KeyCode.UpArrow))
{
upPressed = false ;
}
if(upPressed == true) …Run Code Online (Sandbox Code Playgroud) 如何格式化网格单元格而不是默认的$ s?
我看起来很高,但没有答案.
我有:
{field: "price", title: "Price (£)", width: 95, format: "{0:c}"},
Run Code Online (Sandbox Code Playgroud)
这给了0.00美元,但我怎么得到0.00英镑?
我试过打电话:
kendo.culture("en-gb");
Run Code Online (Sandbox Code Playgroud)
在网格之前,它什么也没做.
我最近用WAMP重新安装了我的服务器,之前我正在使用XAMPP.
在phpmyadmin中,数据库文件的最大上载大小为2,048kb.
我根据几个关于问题的论坛和文章改变了php.ini中的三个变量,重新启动了我的服务器,它没有任何影响.
是否需要在其他地方设置某种环境路径变量等?
我错过了什么
我试图解析一个大小约1GB的制表符分隔文件.
在哪里运行脚本我得到:
Fatal error: Allowed memory size of 1895825408 bytes exhausted (tried to allocate 1029206974 bytes) ...
Run Code Online (Sandbox Code Playgroud)
我的剧本目前只是:
$file = file_get_contents('allCountries.txt') ;
$file = str_replace(array("\r\n", "\t"), array("[NEW*LINE]", "[tAbul*Ator]"), $file) ;
Run Code Online (Sandbox Code Playgroud)
我已经将php.ini中的内存限制设置为-1,然后给了我:
Fatal error: Out of memory (allocated 1029963776) (tried to allocate 1029206974 bytes)
Run Code Online (Sandbox Code Playgroud)
是否有部分打开文件,然后继续下一部分,以便一次使用更少的内存?
我试图将以前仅限日期的字段转换为日期时间字段,但它不起作用.
我有:
schema: {
model: {
id: 'id',
fields: {
dateCreated: {
type: "date", format: "{0:yyyy/MM/dd HH:mm}", editable: "false"
},
...
}
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用,日期格式正确,但时间最终为00:00.
如果我将字段类型更改为"字符串",则数据显示正确,但格式化为SQL方式,即:
2012-05-11 12:56:29
Run Code Online (Sandbox Code Playgroud)
没有"datetime"这样的字段类型,只有"date".如何让它输出我想要的?即:
11/05/2012 12:56
Run Code Online (Sandbox Code Playgroud)
有人有主意吗?
php ×7
laravel ×5
laravel-5 ×3
jquery ×2
kendo-ui ×2
laravel-4 ×2
angularjs ×1
apache ×1
blade ×1
c# ×1
file ×1
formatting ×1
grid ×1
javascript ×1
kendo-grid ×1
laravel-5.1 ×1
php-imagine ×1
phpmyadmin ×1
rbac ×1
wamp ×1