小编Kar*_*ill的帖子

Laravel未知专栏'updated_at'

我刚刚开始使用Laravel,我收到以下错误:

未知列'updated_at'插入gebruikers(naam,wachtwoord,updated_at,created_at)

我知道错误来自迁移表时的时间戳列,但我没有使用该updated_at字段.我曾经使用它,当我按照Laravel教程,但现在我正在制作(或试图制作)我自己的东西.即使我不使用时间戳,我也会收到此错误.我似乎无法找到它被使用的地方.这是代码:

调节器

public function created()
{
    if (!User::isValidRegister(Input::all())) {
        return Redirect::back()->withInput()->withErrors(User::$errors);
    }

    // Register the new user or whatever.
    $user = new User;
    $user->naam = Input::get('naam');
    $user->wachtwoord = Hash::make(Input::get('password'));
    $user->save();

    return Redirect::to('/users');
}
Run Code Online (Sandbox Code Playgroud)

路线

Route::get('created', 'UserController@created');
Run Code Online (Sandbox Code Playgroud)

模型

public static $rules_register = [
    'naam' => 'unique:gebruikers,naam'
];

public static $errors;
protected $table = 'gebruikers';

public static function isValidRegister($data)
{
    $validation = Validator::make($data, static::$rules_register);

    if ($validation->passes()) {
        return true;
    }

    static::$errors = $validation->messages();

    return false;
}
Run Code Online (Sandbox Code Playgroud)

我一定是忘记了什么......我在这里做错了什么?

php mysql laravel laravel-migrations

137
推荐指数
4
解决办法
8万
查看次数

Laravel Redirect返回()消息

当发生致命错误时,我正尝试使用消息重定向到上一页.

App::fatal(function($exception)
{
    return Redirect::back()->with('msg', 'The Message');
}
Run Code Online (Sandbox Code Playgroud)

在视图中尝试访问msg

Sessions::get('msg')
Run Code Online (Sandbox Code Playgroud)

但没有任何东西被渲染,我在这里做错了吗?

laravel laravel-4 laravel-5

129
推荐指数
12
解决办法
34万
查看次数

Laravel检查是否存在相关模型

我有一个Eloquent模型,它有一个相关的模型:

public function option() {
    return $this->hasOne('RepairOption', 'repair_item_id');
}

public function setOptionArrayAttribute($values)
{
    $this->option->update($values);
}
Run Code Online (Sandbox Code Playgroud)

当我创建模型时,它不一定具有相关模型.当我更新它时,我可能会添加一个选项.

所以我需要检查相关模型是否存在,分别更新或创建它:

$model = RepairItem::find($id);
if (Input::has('option')) {
    if (<related_model_exists>) {
        $option = new RepairOption(Input::get('option'));
        $option->repairItem()->associate($model);
        $option->save();
        $model->fill(Input::except('option');
    } else {
       $model->update(Input::all());
    }
};
Run Code Online (Sandbox Code Playgroud)

<related_model_exists>我正在寻找的代码在哪里.

php laravel eloquent laravel-4 laravel-5

128
推荐指数
5
解决办法
11万
查看次数

在表格中选择最后一行

我想检索插入到我的表中的最后一个文件.我知道该方法first()存在并为您提供表中的第一个文件,但我不知道如何获取最后一个插入.

laravel eloquent

126
推荐指数
10
解决办法
25万
查看次数

如何删除URL生成的Laravel中的"public/index.php"?

我需要删除 index.phppublic/index.php从Laravel生成的URL; 通常的道路是localhost/public/index.php/someWordForRoute,应该是这样的localhost/someWordForRoute.

的.htaccess

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes.
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php[L]
Run Code Online (Sandbox Code Playgroud)

应用程序/配置/ app.php

'url' => 'http://localhost',
Run Code Online (Sandbox Code Playgroud)

我怎么能改变呢?

php .htaccess laravel laravel-4 laravel-routing

81
推荐指数
8
解决办法
18万
查看次数

Laravel Request :: all()不应该静态调用

在Laravel中,我试图在我的控制器中调用$input = Request::all();一个store()方法,但是我收到以下错误:

Illuminate\Http\Request::all()假设$this不兼容的上下文,不应静态调用非静态方法

有任何帮助找出解决这个问题的最佳方法吗?(我跟随拉克拉斯特)

php laravel laravel-5

79
推荐指数
4
解决办法
11万
查看次数

我的路线正在返回404,我该如何修复它们?

我刚刚开始学习Laravel框架,我遇到了路由问题.

唯一有效的路线是开箱即用的Laravel附加的默认本地路由.

我在Windows上使用WAMP,它使用PHP 5.4.3和Apache 2.2.22,我也启用了mod_rewrite,并从application.php配置文件中删除了'index.php'以留下空字符串.

我创建了一个名为User的新控制器:

class User_Controller extends Base_Controller {

    public $restful = true;

    public function get_index() 
    {
        return View::make('user.index');
    }
}
Run Code Online (Sandbox Code Playgroud)

我在application/views/user /中创建了一个视图文件,名为index.php,带有一些基本的HTML代码,在routes.php中我添加了以下内容:

Route::get('/', function () {
    return View::make('home.index');
});

Route::get('user', function () {
    return View::make('user.index');
});
Run Code Online (Sandbox Code Playgroud)

http://localhost/mysite/public在我的Web浏览器中访问root()时,第一条路径工作正常,但是当我尝试转到第二条路径时,http://localhost/mysite/public/user我收到404 Not Found错误.为什么会这样?

php routing laravel laravel-3 laravel-routing

73
推荐指数
8
解决办法
13万
查看次数

使用查询生成器或Eloquent加入附加条件

我正在尝试使用Laravel查询生成器的JOIN查询添加条件.

<?php

$results = DB::select('
       SELECT DISTINCT 
          *
          FROM 
             rooms 
                LEFT JOIN bookings  
                   ON rooms.id = bookings.room_type_id
                  AND (  bookings.arrival between ? and ?
                      OR bookings.departure between ? and ? )
          WHERE
                bookings.room_type_id IS NULL
          LIMIT 20',
    array('2012-05-01', '2012-05-10', '2012-05-01', '2012-05-10')
);
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用Raw表达式,但之后会有SQL注入点.我已经尝试了以下查询生成器,但生成的查询(显然,查询结果)不是我想要的:

$results = DB::table('rooms')
    ->distinct()
    ->leftJoin('bookings', function ($join) {
        $join->on('rooms.id', '=', 'bookings.room_type_id');
    })
    ->whereBetween('arrival', array('2012-05-01', '2012-05-10'))
    ->whereBetween('departure', array('2012-05-01', '2012-05-10'))
    ->where('bookings.room_type_id', '=', null)
    ->get();
Run Code Online (Sandbox Code Playgroud)

这是Laravel生成的查询:

select distinct * from `room_type_info`
    left join `bookings` 
on `room_type_info`.`id` = `bookings`.`room_type_id` …
Run Code Online (Sandbox Code Playgroud)

laravel laravel-4 laravel-query-builder

72
推荐指数
6
解决办法
12万
查看次数

Laravel 4除主页外的所有路由导致404错误

我使用Composer安装了Laravel 4并设置了虚拟主机.目前,只有根路由正在工作:

<?php

Route::get('/', function()
{
    return View::make('hello');
});
Run Code Online (Sandbox Code Playgroud)

这不是:

Route::get('/hello', function()
{
    return View::make('hello');
});
Run Code Online (Sandbox Code Playgroud)

我试图打是TasksController/tasks:

Route::resource('tasks', 'TasksController');
Run Code Online (Sandbox Code Playgroud)

这也给了我404错误.我能做错什么?我在项目的根目录下有一个默认的.htaccess文件:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

我在Mac上使用localhost.

routing http-status-code-404 laravel laravel-4 laravel-routing

59
推荐指数
9
解决办法
6万
查看次数

Laravel逃离刀片模板中的所有HTML

我正在Laravel中构建一个小型CMS,我试图显示内容(存储在数据库中).它显示HTML标记而不是执行它们.它就像所有打印数据都有一个自动html_entity_decode.

<?php

class CmsController extends BaseController
{
    public function Content($name)
    {    
        $data = Pages::where('CID', '=', Config::get('company.CID'))
            ->where('page_name', '=', $name)
            ->first();

        return View::make('cms.page')->with('content', $data);
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试使用大括号打印内容.

{{ $content->page_desc }}
Run Code Online (Sandbox Code Playgroud)

和三重大括号.

{{{ $content->page_desc }}}
Run Code Online (Sandbox Code Playgroud)

他们给出了相同的结果.我需要执行这些HTML标记而不是转义它们.

php laravel laravel-4 laravel-blade

58
推荐指数
5
解决办法
8万
查看次数