laravel

Laravel sort conversations by last message

不打扰是莪最后的温柔 提交于 2021-01-28 09:23:41
问题 I have a Conversation model that has many ConversationMessage models. Now I want to sort the conversations based on the last message of the conversation. Basically like WhatsApp. How do I build the query? As a sidenote to my code: Conversation contains a user ( user_id ) and a company associated ( company_id ). Company has a belongsToMany relation to user. Conversation::whereHas('company', function ($q) use ($userId) { $q->whereHas('users', function ($q1) use ($userId) { $q1->where('users.id'

Laravel 3 way intermediate pivot table

人盡茶涼 提交于 2021-01-28 09:16:49
问题 I am having trouble defining the relationships in my Eloquent Models when using a 3 way intermediate pivot table. Here are the 4 tables in my database: users - id - name instruments - id - key instruments_users - id - user_id - instrument_id - level_id levels - id - key Instruments keys can be: guitare , piano , trumpet , etc. Levels keys can be: beginner , intermediate , expert , etc. Each user can play of 1 or more instrument. For each played instrument (relationship), we attribute a level

Laravel Auth Problem for Web and Api Routes

微笑、不失礼 提交于 2021-01-28 09:11:40
问题 Unfortunately, I can't find a solution for a user case, which must actually occur frequently. To describe it best, I put here the structure of my routes (web and api) of my laravelapp: routes/web.php get(start|products|product/{id}|contact|inprint|login|register) get(checkout|checkout/(any))->middleware( auth ) // Checkout is a VUE App routes/api.php // only the Vue App use the api get(user|user_orders|user_address) ->middleware( auth ) post (purchase_order) -> middleware(auth) As you can

Laravel 3 way intermediate pivot table

此生再无相见时 提交于 2021-01-28 09:10:18
问题 I am having trouble defining the relationships in my Eloquent Models when using a 3 way intermediate pivot table. Here are the 4 tables in my database: users - id - name instruments - id - key instruments_users - id - user_id - instrument_id - level_id levels - id - key Instruments keys can be: guitare , piano , trumpet , etc. Levels keys can be: beginner , intermediate , expert , etc. Each user can play of 1 or more instrument. For each played instrument (relationship), we attribute a level

How to check If the current app process is running within a queue environment in Laravel

依然范特西╮ 提交于 2021-01-28 09:09:47
问题 I applied a global scope to my models via a trait, but I don't want the global scope applied when the model is called/processed from my Redis queue. How do I detect if the current instance is a queue process? just like we have this if (App::environment('local')) { // The environment is local } to detect if the app is running in local or production. 回答1: Simply call: app()->runningInConsole(); to check if execution is happening via cli. 来源: https://stackoverflow.com/questions/61243351/how-to

Laravel : How put a date from order placed

陌路散爱 提交于 2021-01-28 09:06:33
问题 I'm trying to put the date order placed using Carbon. my-order.blade.php @foreach ($order->products as $product) <div>{{ presentDate($order->created_at) }}</div> <div>Total : {{ $product->price }} €</div> <div>Quantity: {{ $product->pivot->quantity }}</div> </div> OrderProduct.php use Carbon\Carbon; function presentDate($date) { return Carbon::parse($date)->format('M d, Y'); } Maybe I have to put the function in another place ? Thanks for your help. 回答1: You can leverage Laravel Accessors &

Nesting sections in Blade

…衆ロ難τιáo~ 提交于 2021-01-28 08:56:23
问题 I'm looking at how Blade implements the @section, but it works a little different than I'm used to with Twig. It seems that you can't nest @sections in each other. Example: _layout.blade.php (basic layout file) <html> //favicons //meta content //other basic shizzle <head> <title>overal</title> </head> <body> @yield('body_content') </body> </html> website.blade.php (specific implementation) @extend('_layout.blade.php') @section('body_content') <div class=""> website-header </div> <div class=

React Router does not recognize direct address line changing in laravel

不羁岁月 提交于 2021-01-28 08:54:52
问题 I use React Router and Laravel. When I navigate throught Link elements all OK, but when I change browser address line to manually show another component Laravel shows it defalt 404 page. This is default web.php content, in welcome.blade.php I inlcude js/app.js file: Route::get('/', function () { return view('welcome'); }); This is my App.js content: import React from 'react'; import { Switch, Route } from "react-router-dom"; import Signin from "../../containers/Signin"; import Signup from "..

Unable to authenticate laravel private channel using Laravel echo server, redis and socket.io

て烟熏妆下的殇ゞ 提交于 2021-01-28 08:52:12
问题 I am using Laravel Echo server, redis and socket.io for Chat Messages. I am broadcasting event using. event(new MessageSent($messageThread)); This is private channel with method brodcastOn as follows: public function broadcastOn() { return new PrivateChannel('message.' . $this->broadcastUser->id); } My routes/channels.php looks like: Broadcast::channel('message.*', function ($user, $id) { return (int) $user->id === (int) $id; }); Below is my laravel-echo-server.json : { "authHost": "http:/

How can I get the value from a cell in a table?

喜欢而已 提交于 2021-01-28 08:48:56
问题 I have read all the related posts and used them with no success. Obviously I'm not a javascript expert. I had tried with option, and selectedItem, but don't know how to extract the select object to use it. This is a fraction of my code, I hope you can help me. <div class="card-body"> <table class="table" id="products_table"> <thead> <tr> <th>Descripción</th> <th>Suaje</th> <th>Cantidad/etiq.</th> <th>Importe</th> <th>Sustrato</th> <th>Sustrato $</th> <th>Acabado</th> <th>Acabado $</th> <th