小编jrs*_*nga的帖子

流明:如何从路由传递参数到控制器

从我的路线我需要将$ page的值传递给控制器

路线:

$app->get('/show/{page}', function($page) use ($app) {

  $controller = $app->make('App\Http\Controllers\PageController');
  return $controller->index();

});
Run Code Online (Sandbox Code Playgroud)

控制器:

public static function index(){

  /** how can I get the value of $page form here so i can pass it to the view **/

  return view('index')->with('page', $page);

}
Run Code Online (Sandbox Code Playgroud)

laravel lumen

6
推荐指数
1
解决办法
5424
查看次数

BackboneJS:迭代模型属性并更改值

我想创建一个功能,如toJSON()返回和编辑模型的功能.

我的问题是如何迭代模型的属性并编辑您选择的属性的特定值.

如果有一个模型,例如:

Item = Backbone.Model.extend({
    defaults: {
        name: '',
        amount: 0.00
    },
    toHTML: function(){
        // i think this is the place where
        // where i can do that function?

        //
        console.log(this.attribute)
    }
});
var item = new Item;

item.set({name: 'Pencil', amount: 5}): 

item.toJSON();
-> {name: 'Pencil', amount: 5}

// this is the function
item.toHTML();
-> {name: 'Pencil', amount: 5.00}
Run Code Online (Sandbox Code Playgroud)

javascript backbone.js underscore.js backbone-model

1
推荐指数
1
解决办法
5432
查看次数

Laravel:如何将主键和外键设置为字符串

我没有使用id的自动增量而是使用32个字符的唯一ID.因此,当我创建一个关系和查询时,我得到一个null因为我的FK期望我的模型

class User extend Eloquent {
    public $incrementing = false; 
}

class Reservation extend Eloquent {
    public $incrementing = false; 
}
Run Code Online (Sandbox Code Playgroud)

所以当我查询这个

$reservations = Reservation::with('user')->where('user_id', '=', '22beb4892ba944c8b1895855e1d4d1ad')->get();
i could not retrieve the users information but the reservations info is working fine
when i try to listen for query. eg:
Event::listen('illuminate.query', function($query, $bindings, $time, $name){
    var_dump($query);
    var_dump($bindings);
});
Run Code Online (Sandbox Code Playgroud)

我明白了

string(46) "select * from `reservation` where `user_id` = ?"
array(1) {
  [0]=>
  string(36) "22beb4892ba944c8b1895855e1d4d1ad"
}
string(53) "select * from `user` where `user`.`id` …
Run Code Online (Sandbox Code Playgroud)

laravel laravel-4

1
推荐指数
2
解决办法
1万
查看次数