小编ech*_*shu的帖子

laravel 5中应用程序URL的含义是什么?

Config/app.phplaravel源中,实际使用的是url什么?

它说要使用的应用程序URL artisan command line tool,那么实际应该是什么?

我的意思是应该是http://mydomainname.com或应该是/var/www/laravel//var/www/laravel/public

当前配置

/*
|--------------------------------------------------------------------------
| Application URL
|--------------------------------------------------------------------------
|
| This URL is used by the console to properly generate URLs when using
| the Artisan command line tool. You should set this to the root of
| your application so that it is used when running Artisan tasks.
|
*/

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

如果我的应用程序源位于/var/www/目录并且laravel公用文件夹是/var/www/laravel/public ,http://mydomainname.com则指向在/var/www/laravel/public目录中解析

使用案例: …

php queue laravel laravel-5 artisan

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

创建包含关系的Eloquent对象

我对opps和laravel都很陌生.所以,将值插入我的usersprofiles表中的hav OneToOne关系,这是我的store()方法看起来像

public function store(Requests\StoreNewUser $request)
{
    // crate an objct of user model
        $user = new \App\User;
        // now request and assign validated input to array of column names in user table
        $user->first_name = $request->input('first_name');
        $user->last_name = $request->input('last_name');
        $user->email = $request->input('email');
        $user->password = $request->input('password');
        /* want to assign request input to profile table's columns in one go 
        */
        $user->profile()->user_id = $user->id; // foreign key in profiles table
        $user->profile()->mobile_no = $request->input('mobile'); 
        dd($user); // …
Run Code Online (Sandbox Code Playgroud)

php foreign-key-relationship laravel eloquent laravel-5

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

使用雄辩的方法从laravel 5中的刀片运行选择查询的正确方法

基于compact刀片内部方法所提供的Model变量上的某些选择过滤器,检索列值的正确方法是什么。(Larevl 5)
我读到从视图查询数据库的正确做法是不正确的,因此我遵循惯例使用所需的数据compact来查看视图

但是,在需要根据第一张表的刀片内的foreach循环中返回的某些列值查询另一张表的情况下,我无法找出正确的方法

示例:我有两个模型UserGroup
架构 User

id,name,email,group_id
Run Code Online (Sandbox Code Playgroud)

计划团体表
idgroupname

这是UserController-> compact方法

$users = \App\User::all(array('id','name','email','group_id'));
$groups = \App\Group::all(array('id','group_name'));
return view('user.index',  compact('users','groups'));
Run Code Online (Sandbox Code Playgroud)

刀片如何需要它们

@foreach ($users as $user)
      <tr>
            <th>{{$user->id}}</th>
            <th>{{$user->name}}</th>
            <th>{{$user->email}}</th>
            <th>
              <!-- Here i need to run something like 
select group_name from group where id = $user->id -->
{{$groups->where('id','=',$user->group_id) }}

            </th>
            <th>Actions</th>
        </tr>
        @endforeach
Run Code Online (Sandbox Code Playgroud)

我知道这会返回一个数组,我在这里有两个问题

  1. 如何group_name从基于组的“组模型”中获取列的值。id= $user->id在foreach循环中
  2. 由于从刀片服务器查询db是一种不好的做法,因此,当尚不知道where子句参数时,如何通过契约将数据从控制器传递到刀片服务器,如何利用模型中的值。

编辑1:

我将最后一个组查询修改为

 <th>@if($groups->where('id','=',$user->group_id))
                  @foreach($groups as $group)
      {{$group->group_name}} …
Run Code Online (Sandbox Code Playgroud)

php mysql laravel eloquent laravel-5

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

获取超过 15 分钟的所有 WP 帖子

我想过滤 WP_Query 以检索(post_type = shop_order)具有超过 15 分钟的特定状态的所有 woocommerce 订单。

即所有上次修改日期或之前的帖子(现在 - 15 分钟)// 希望我清楚。

下面是我尝试过的

 function filter_where($where = '') {
            //posts in the last 15 minutes
           $where .= " AND post_modified > '" . date('Y-m-d', strtotime('INTERVAL 15 MINUTE')) . "'";
            return $where;
        }
        add_filter('posts_where', 'filter_where');

 $args = array(
    'post_type'         => 'shop_order',
    'post_status'       => 'publish',
            'posts_per_page' => 10,
    'tax_query' => array(
                array(
                    'taxonomy' => 'shop_order_status',
                    'field' => 'slug',
                    'terms' => array('completed')
                )
            )
);
$loop = new WP_Query( $args …
Run Code Online (Sandbox Code Playgroud)

php mysql wordpress

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

在为两个时间戳列laravel 5播种时,数据库迁移会引发错误

我扩展了默认迁移,为我的用户表包含了一些额外的表字段.

我希望拥有created_at和作为价值观的updated_at领域timestamps.

这是我的代码

<?php

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

 class CreateUsersTable extends Migration {

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('users', function(Blueprint $table)
    {
        $table->bigIncrements('id');
                    $table->bigInteger('group_id');
        $table->string('fname',255);
        $table->string('lname',255);
        $table->string('email',255)->unique();
        $table->string('password', 60);
        $table->boolean('active');
        $table->string('gravtar',255)->nullable();
        $table->rememberToken();
        $table->timestamps('created_at');
        $table->timestamps('updated_at');

    });
}

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

}
Run Code Online (Sandbox Code Playgroud)

障碍是使用两个时间戳列不迁移表并抛出此异常

[PDOException]
SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'created_at'
Run Code Online (Sandbox Code Playgroud)

看,我只有一个名称列 …

php mysql create-table laravel-5 laravel-migrations

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

未定义在laravel 5中将数据从控制器传递到刀片时的可变错误

行,

这是我的index()方法UserController

public function index()
{

    $name = 'echoashu';

     return view('home', compact('name'));
}
Run Code Online (Sandbox Code Playgroud)

就这么简单,这里是我的home.blade.php代码

  <span class="info-box-number">{{$name}} </span>
Run Code Online (Sandbox Code Playgroud)

这必须按照文档理想工作,但它返回未定义的变量错误

Undefined variable: name (View: C:\xampp\htdocs\laravel1\resources\views\home.blade.php)
Run Code Online (Sandbox Code Playgroud)

任何猜测?

php laravel laravel-5

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