小编Far*_*had的帖子

在 laravel elequent 中查询 json 列

我有一个名为的模型orders,它有一个infojson 列。在该 json 中我有一个名为 的属性id。现在我想检索 id 为 的所有订单6。所以这就是我的做法,如下所示:

  $order = \DB::table('orders')
                ->where('info.id',$value)
               // ->where('info->id',$value)
//            ->whereRaw('JSON_EXTRACT(`info` , "$.id") = '.$value)
                ->first();
Run Code Online (Sandbox Code Playgroud)

第三个whereRaw正在工作,但我认为它有一个错误,因为在我的验证中,第三个或第四个返回了这个错误,这很奇怪:

Column not found: 1054 Unknown column '6112 ' in 'where clause' (SQL: select * from `orders` where JSON_EXTRACT(`info` , "$.id") = 6112  limit 1)
Run Code Online (Sandbox Code Playgroud)

它有些错误地将列值误认为是列名,这很奇怪,因为当我从查询中获取值时,它在第一个上工作,dd但它像第四个一样中断。现在我想知道是否有更简单的解决方案可以在 json 字段上使用 where 或 whereRaw 有什么问题

php mysql laravel mysql-json

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

vuejs 在选择后获取日期选择器的值

在vue js中,我想获得2个日期选择器的结果并获得它们之间的不同日期,但问题是我想在提交表单之前执行此操作,我的意思是当用户选择日期时我想计算天数并根据价格给出价格我使用波斯日期选择器,如果有帮助的话,我将其添加到下面:

https://github.com/talkhabi/vue-persian-datetime-picker
Run Code Online (Sandbox Code Playgroud)

这是我的 html 标记:

<div class="row">
                <div class="col-lg-6">
                    <label>start reserve</label>
                    <date-picker :auto-submit="true" v-model="date" :max="available_end.toString()"
                                 :min="reserve_end.toString()"></date-picker>
                </div>
                <div class="col-lg-6">
                    <label>end reserve</label>
                    <date-picker :auto-submit="true" v-model="date2" :max="available_end.toString()"
                                 :min="reserve_end.toString()"></date-picker>
                </div>
            </div>
Run Code Online (Sandbox Code Playgroud)

这是 vuejs 部分:

data(){
return {
date: '',
date2:'',
}
},
 components: {
        datePicker: VuePersianDatetimePicker
    },
Run Code Online (Sandbox Code Playgroud)

该代码包含更多内容,因此我将其剪切以便更好地阅读,并且我尝试使用 date 和 date2 但它们似乎不起作用。

javascript php laravel vue.js

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

php工匠望远镜:安装不在laravel中发布资产

我有一个laravel 6的应用程序,我想安装在望远镜中,我做了所有喜欢的命令composer updatecomposer dump-autoload,然后我安装望远镜的每一件事情是要罚款,当我跑php artisan telescope:install我得到以下信息:

Publishing Telescope Service Provider...
Publishing Telescope Assets...
Publishing Telescope Configuration...
Telescope scaffolding installed successfully.
Run Code Online (Sandbox Code Playgroud)

但它不会生成配置文件和迁移,所以当我运行时,php artisan migrate 我收到此消息:

nothing to migrate
Run Code Online (Sandbox Code Playgroud)

因此我无法访问望远镜。请指教 。

php mysql laravel

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

Laravel 迁移外键不起作用

我正在 laravel 上创建一个新的应用程序,我正在编写迁移,我想为我的列设置外键,所以我正在做如下:

   Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->integer('type_id');
            $table->string('name');
            $table->integer('status_id')->default(0);
            $table->integer('category_id')->default(0);
            $table->integer('store_id');
            $table->timestamps();
            $table->foreign('status_id')->references('id')->on('product_statuses');
            $table->index('status_id');
            $table->foreign('type_id')->references('id')->on('product_types');
            $table->index('type_id');
            $table->foreign('category_id')->references('id')->on('product_categories');
            $table->index('category_id');
            $table->foreign('store_id')->references('id')->on('stores');
            $table->index('store_id');
Run Code Online (Sandbox Code Playgroud)

但这些都不起作用,因为我检查它phpmyadmin让我插入任何数字而不是来自status_id例如的项目,当我在design选项卡中检查它时,我没有看到表格之间的关系。#编辑

添加product_types迁移:

 /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('product_types', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->timestamps();
        });
    }
Run Code Online (Sandbox Code Playgroud)

关于引擎,我将 wamp 与 mysql v8 一起使用,我认为它支持 fk 功能

mysql migration laravel

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

此集合实例 Laravel 关系上不存在属性 [X]

我在 laravel 5.6 中使用了很多 realtions,当我添加 $phonebooks 时,我看到所有的关系都正常工作,一切都很好,但是当我尝试在视图中显示它们时,我得到此集合中不存在属性的错误这是关系代码

public function client() {
    return $this->hasMany('App\Client','id' , 'client_id');
}
Run Code Online (Sandbox Code Playgroud)

这是控制器

public function index()
{    $phonebooks = Phonebook::with('client')->get();

    return view('admin.phonebooks.index',compact('phonebooks',$phonebooks));
}
Run Code Online (Sandbox Code Playgroud)

最后这是我如何尝试在视图中展示它们

<tbody>
@foreach($phonebooks as $phonebook)
    <tr>
        <th scope="row">{{$phonebook->id}}</th>
        <th scope="row">{{$phonebook->title}}</th>
        <td><a href="/admin/phonebooks/{{$phonebook->id}}">{{$phonebook->description}}</a></td>
        <td>{{$phonebook->calldate}}</td>
        <td>{{$phonebook->created_at->toFormattedDateString()}}</td>

        <td>{{ $phonebook->client->title}}</td>
        <td>
            <div class="btn-group" role="group" aria-label="Basic example">
                <a href="{{ URL::to('admin/phonebooks/' . $phonebook->id . '/edit') }}">
                    <button type="button" class="btn btn-warning">???????</button>
                </a>&nbsp;
                <form action="{{url('admin/phonebooks', [$phonebook->id])}}" method="POST">
                    <input type="hidden" name="_method" value="DELETE">
                    <input type="hidden" name="_token" value="{{ csrf_token() }}">
                    <input type="submit" class="btn btn-danger" …
Run Code Online (Sandbox Code Playgroud)

php controller view laravel

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

how to access the defined relation in blade view laravel 5.6

i want to access the defined relation in my blade view and show it i am doing like this in my invoice model

public function users() {
    return $this->hasone('App\Client','id','client_id');
}
Run Code Online (Sandbox Code Playgroud)

and here in invoice controller

 public function show(Invoice $invoice)
{
    $clients = Invoice::with('users')->get();
    return view('admin.invoices.show', compact('invoice', $invoice),compact('clients',$clients));
}
Run Code Online (Sandbox Code Playgroud)

and finally in my view i did this

<td>{{ $clients->users->first()->title }}</td>
Run Code Online (Sandbox Code Playgroud)

but when i try to view i get this error

Property [users] does not exist on this collection instance
Run Code Online (Sandbox Code Playgroud)

when i …

php controller view laravel laravel-blade

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

如何在另一个 prop 中使用 prop 作为 vuejs 中的默认值

我正在使用来自 git hub 的这个包作为 vuejs 的负加输入,在 v2 文件夹示例中有一个名为 plusminusfield.vue 的示例文件,这是我用来使用它的:

 export default {
    props: {



        value: {
            default: 0,
            type: Number
        },
       base_capacity: {
            type: Number,
            required: true
        },
        min: {
             default: here I want to use the sent variable which is defined above and that is base_capacity 
 if I send a hard code like 5 it works well but I want to make it dynamic
             type:Number
        },
        max: {
            default: 22,
            type: Number
        },
    },
    data(){
        return …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js

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

Laravel 日志系统与 Logstash

我有一个 Laravel 应用程序,我想将日志存储到 Logstash 中并在 kibana 中查看它们,我在网上搜索了很多以找到它的解决方案,但我没有找到任何好的来源,是否有任何包可以使用 Laravel登录logstash ??? 顺便说一句,我的 Logstash 和 kibana 运行没有任何问题,我现在只需要一个数据源。这是我正在运行的 elstic 搜索:

    {
name: "5351ced3b7a4",
cluster_name: "elasticsearch",
cluster_uuid: "Ej5TRN8CQyGvemZlT3gAFA",
version: {
number: "7.1.1",
build_flavor: "oss",
build_type: "tar",
build_hash: "7a013de",
build_date: "2019-05-23T14:04:00.380842Z",
build_snapshot: false,
lucene_version: "8.0.0",
minimum_wire_compatibility_version: "6.8.0",
minimum_index_compatibility_version: "6.0.0-beta1"
},
tagline: "You Know, for Search"
}
Run Code Online (Sandbox Code Playgroud)

编辑,因为答案解释了我的做法,现在我在 laravel 的日志中收到此错误:

[2019-08-05 14:16:17] laravel.INFO: Hello logstash!  
Run Code Online (Sandbox Code Playgroud)

编辑:日志配置文件:

<?php

use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;

return [

/*
|--------------------------------------------------------------------------
| Default Log Channel
|--------------------------------------------------------------------------
|
| This option defines the default …
Run Code Online (Sandbox Code Playgroud)

php logging elasticsearch laravel logstash

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

如何在laravel中接收2个日期之间的所有日期

在我看来,我有如下两个日期:

{{$property->start_date }} //which is for example 3/20/219
Run Code Online (Sandbox Code Playgroud)

和另一个日期

{{$property->end_date }} //which is for example 3/28/219
Run Code Online (Sandbox Code Playgroud)

现在我想知道如何将这 8 天的差异打印为 8 col-lg-1 ,就像下面的代码一样

@while($property->start_date  <= $property->end_date)

//here i want to print dates in col-lg-1 i dont know how to access the day and if the while loop is working right or no
Run Code Online (Sandbox Code Playgroud)

我怎样才能在刀片中实现这一点,考虑到我在我看来正在这样做,并且在我看来这样做是否合理。

php laravel

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

Laravel 中如何按集合的关系对集合进行排序

我的酒店有一个复杂的过滤器,最后我有一个集合,我想按嵌套关系对父关系进行排序,所以这里我有如下:

  public function resultFilter($from_date, $to_date, $bed_count, $city_id, $stars, $type_id, $hits, $price, $accommodation_name, $is_recommended, $start_price, $end_price, $has_discount, $facility_id)
    {
//        $data = QueryBuilder::for(Accommodation::class)
//            ->allowedFilters(['city_id','grade_stars','accommodation_type_id'])
//            ->allowedIncludes('gallery')
//            ->when($bed_count, function ($q, $bed_count) {
//                $q->with([
//                    'accommodationRoomsLimited' => function ($q) use ($bed_count) {
//                        $q->where('bed_count', $bed_count);
//                    }
//                ]);
//            })
//            ->paginate(10);
//        ->get();
//            ->orderBy('hits','DESC')->paginate(10);
        $data = Accommodation::with(['city','accommodationFacilities', 'gallery', 'accommodationRoomsLimited.discount', 'accommodationRoomsLimited', 'accommodationRoomsLimited.roomPricingHistorySearch' => function ($query) use ($from_date, $to_date) {
            $query->whereDate('from_date', '<=', $from_date);
            $query->whereDate('to_date', '>=', $to_date);
        }])->when($bed_count, function ($q, …
Run Code Online (Sandbox Code Playgroud)

php laravel

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