小编Lau*_*nce的帖子

如何在Laravel中创建无限子页面的路由?

有没有办法捕获无限级别的子页面URL.我的应用程序允许任何用户创建任何级别的子页面.在我的页面表中,我有parentID.

/{page}/{subpage} // this captures 2 level of pages
/{page} // this captures 1 level of page
Run Code Online (Sandbox Code Playgroud)

我想要捕获范围从的所有URL

site.com/food/healthy/fruit/red/apple site.com/fruit/organge site.com/grapes site.com/a/b/c/d/e/f/g/h/i/ j等等.

什么是最有效的方式?

php laravel laravel-4

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

通过Cronjob发行Running Artisan Command

我有一个噩梦得到一个crontab/cronjob来运行Artisan命令.

我有通过cronjob运行的另一个Artisan命令没有问题但是第二个命令不会运行.

首先,当我执行'crontab -e'并编辑要包含的文件时:

0 0 * * * /usr/local/bin/php  /home/purple/public_html/artisan feeds:send
Run Code Online (Sandbox Code Playgroud)

cronjob根本不运行.

如果我去cPanel并在那里添加cronjob,它运行但我收到以下错误:

open(public/downloads/feeds/events.csv): failed to open stream: No such file or directory
Run Code Online (Sandbox Code Playgroud)

问题是文件存在且目录具有正确的权限.如果我以root身份通过SSH登录或者用户紫色(php artisan feeds:send)运行命令,该命令运行完美并完成其任务没有问题.

如果在cPanel中,我编辑cronjob使用:

0 0 * * * php  /home/purple/public_html/artisan feeds:send
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

 There are no commands defined in the "feeds" namespace.
Run Code Online (Sandbox Code Playgroud)

有趣的是,我的其他命令在crontab文件中注册并且工作,并且在cPanel中根本没有引用.

任何帮助将非常感激.为简洁起见,我已经包含了命令使​​用的命令和模型.

Feed.php型号:

http://laravel.io/bin/1e2n

DataFeedController.php控制器:

http://laravel.io/bin/6x0E

SendFeeds.php命令:

http://laravel.io/bin/BW3d

启动/ artisan.php:

http://laravel.io/bin/2xV3

FeedInterface.php接口:

http://laravel.io/bin/LxnO

正如您所看到的,有一个GetRates命令,它可以工作.

cron crontab laravel-4

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

Laravel使用多个主键迁移创建表

我发出命令:

php artisan generate:scaffold order --fields="customer_id:integer(11), order_date:date, notes:text”
Run Code Online (Sandbox Code Playgroud)

当它进行迁移时,它以错误结束:

General error: 1 table "orders" has more than one primary key (SQL: create table "orders" ("id" integer not null primary key autoincrement, "customer_id" integer not null primary key autoincrement, "order_date" date not null, "notes" text not null))
Run Code Online (Sandbox Code Playgroud)

我试图customer_id在模式中引用一个Customer模型和相应的表.但是,它不应该是orders表的主键.

以下是up()阻止迁移运行的代码:

    Schema::create('orders', function(Blueprint $table)
    {
        $table->increments('id');
        $table->integer('customer_id', 11);
        $table->date('order_date');
        $table->text('notes');
        $table->timestamps();
    });
Run Code Online (Sandbox Code Playgroud)

我如何让它工作?

php laravel laravel-4

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

许多人加入Laravel Eloquent

我正在使用Laravel 4.1,我想与Eloquent建立联系:所以我有3个表:

表1(池):id,name

表2(贡献):id,amount,pool_id,contributer_id

表3(贡献者):id,last_name

顺便说一句,我有3个模型:池,贡献者和贡献,提前谢谢.

laravel-4

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

运行本地开发服务器的artisan命令是什么http://local.dev/test-laravel/?

http://local.dev/test-laravel/这样的地址运行本地开发服务器的artisan命令是什么?

test-laravel是我安装laravel的文件夹.

当我运行一个命令,就像php artisan serve --host=local.dev/test-laravel/它说服务器开始于http://local.dev/test-laravel:8000(这不起作用)

理想情况下,网址应为http://local.dev:8000/test-laravel

我该如何实现这一目标?

php laravel

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

在 Laravel 中循环遍历错误消息而不使用 withErrors($validator) - foreach

如何从失败的验证器查看 Laravel 控制器中的错误?

我知道我可以使用这个:

return Redirect::route('account-create')->withErrors($validator)->withInput();
Run Code Online (Sandbox Code Playgroud)

但是我需要一个字符串以相同的方法对其进行操作,那么如何使用 foreach 迭代错误并将其附加到单个字符串?

php laravel

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

在laravel中定义全局变量

型号:Comment.php

class Comment extends Eloquent {
    protected $table = 'comments';
    public $timestamps = true;
}
Run Code Online (Sandbox Code Playgroud)

控制器:PageController.php

class PageController extends BaseController {
    $top_comments = Comment::take(3)->get();
    return View::make('page', array('top_comments' => $top_comments));
}
Run Code Online (Sandbox Code Playgroud)

查看:page.blade.php

@foreach ($top_comments as $comment)
    user #{{ $comment->user_id }}:<br />
    {{ $comment->comment}}
@endforeach
Run Code Online (Sandbox Code Playgroud)

这与page.blade.php我可以定义为route(/page)的视图完美配合.但是,我似乎无法弄清楚如何在全球范围内实现这一目标.

示例:我希望能够在我的文件中使用@foreach包含.现在,如果我是使用上面的,它的伟大工程上,但不是在,,$top_commentsmaster.blade.php/page//about/tos

php laravel laravel-3

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

Laravel迁移外键问题

我已经使用类别迁移创建了类别表,然后我尝试使用另一个迁移创建产品表,其中包含产品表中的外键关键字category_id到产品表中的id.

请在下面找到我的迁移.

Categories migration

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCategoriesTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('categories',function(Blueprint $table)
        {
            $table->increments('id');

            $table->string('category_name', 255);
            $table->string('category_description', 255);

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('categories');
    }

}

Products migration

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProductsTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function …
Run Code Online (Sandbox Code Playgroud)

laravel laravel-4

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

设置Laravel的Auth用户

我正在使用Laravel的Auth类来验证我网站上的用户(基本Auth::attempt(...)内容)。

最近有一个新的要求(是利益相关者!),现在需要用户创建新用户(辅助用户)。由于主要用户的登录是通过第三方系统进行的,因此我无法将辅助用户与主要用户存储在一起(并重用当前的身份验证系统)。

我想到的是以某种方式告诉Auth类登录并在Auth::user()方法上强制设置用户。

有没有办法做到这一点?

laravel-4

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

升级到Laravel 5.1 - 方法[验证器]不存在

昨晚,我将应用程序从5.0升级到5.1.

除注册外,一切似乎都运转正常.

在输入信息和注册时,我收到此错误:

BadMethodCallException in Controller.php line 282:
Method [validator] does not exist.
Run Code Online (Sandbox Code Playgroud)

无法弄清楚我在哪里解决这个问题.

RegistersUsers.php

    namespace Illuminate\Foundation\Auth;

    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\Auth;
    use App\Services\Registrar;

    trait RegistersUsers
    {
        use RedirectsUsers;

    public function postRegister(Request $request)
        {
            $validator = $this->validator($request->all());

            if ($validator->fails()) {
                $this->throwValidationException(
                    $request, $validator
                );
            }

            Auth::login($this->create($request->all()));

            return redirect($this->redirectPath());
        }
}
Run Code Online (Sandbox Code Playgroud)

Controllers.php

public function __call($method, $parameters)
    {
        throw new BadMethodCallException("Method [$method] does not exist.");
    }
Run Code Online (Sandbox Code Playgroud)

laravel laravel-5

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

标签 统计

laravel ×7

laravel-4 ×6

php ×5

cron ×1

crontab ×1

laravel-3 ×1

laravel-5 ×1