eloquent

How to query only by month on date input and ignore the year and day considering indexing or performance on database in laravel

为君一笑 提交于 2019-12-25 07:54:50
问题 I have this table training_schedules id course_reference start_date(date) end_date(date) year_id(int, fk) on my form, I have dropdownlist for the month, and another one for the year. Now as you can see there is a mismatch on the month from form and database column . How can I filter the start_date or end_date column using only the integer value from the dropdownlist and ignore the day and year part of the db column? I saw some examples but using raw query and using date functions of database

Want to fetch data from three tables in laravel 5.2

旧时模样 提交于 2019-12-25 07:20:04
问题 I have a little query in which I need your help, Please have a look below. I want to fetch all the data from the products table with some conditions like city, price, Type, category. I can fetch all the data but I can't fetch the category data from the product model with all other conditions. Below is my tables and Eloquent relations. I am using Laravel 5.2. products ->foreign_key('subcategory_id') subcategories ->foreign_key('category_id') category users: ->foreign_key('product_id') users

Laravel - Eloquent Create or Update Model

北战南征 提交于 2019-12-25 07:13:45
问题 I am trying to create a view counter for product views, so I need to track how many times the product is opened. So, what I have done is create a new table- Schema::create('user_add_views', function (Blueprint $table) { $table->integer('user_id') ->unsigned() ->index(); $table->integer('add_id') ->unsigned() ->index(); $table->integer('total_view') ->integer() ->default(1); //Removed all keys for making things faster //Foreign Keys $table->foreign('user_id') ->references('id') ->on('users');

Laravel / Carbon adding two timestamps together?

三世轮回 提交于 2019-12-25 06:13:11
问题 I am working on a system where people can start and stop something which calculates the time it has taken them. This is done by: When the "Start" button is pressed, a date is added into the database table for that row. When the "Stop" button is pressed, a date (end date)is added then I calculate the difference by: $startTime = \Carbon\Carbon::parse($task->date_start); $finishTime = \Carbon\Carbon::parse($task->date_complete); $totalDuration = $finishTime->diffInSeconds($startTime); And also

Caching issue in angularJS application

风格不统一 提交于 2019-12-25 06:06:16
问题 I've an admin panel which is a pure angularJS application, which uses REST api for data manipulation. REST api is built using SlimAPI framework and Laravel's Eloquent ORM. I'm facing caching issue in admin panel. Even though if a add new content to the system, it'll not show up in the list page until and unless I clear the cache and refresh it. I cannot ask my client to clear the cache everytime when they add new content to the system. My questions are: Is there any way to refresh the cache

retrieving multiple records associated to multiple records laravel 4.2

我与影子孤独终老i 提交于 2019-12-25 05:34:15
问题 recently i asked this question which got one answer but unfortunately didn't solve the problem, after that i got no more answers and i really need to fix this problem i have. Alright so i have to make a quiz website for my school in which a user should be able to play the quiz, this page need to show the quiz name, the questions associated to the quiz and the answers associated to the questions. I can show the quiz name no problem and i can show the questions aswell, but for some reason only

Laravel fails to deserialize model with mysql's POINT column

被刻印的时光 ゝ 提交于 2019-12-25 04:59:12
问题 I have a model where column location represents coordinates. This column can be null. When it is null everything is fine, but when there is some data, then: If it is used inside internal laravel events (which does not implement ShouldBroadcast) then I have to add use SerializesModels , otherwise field is not deserialized, exception is thrown invalidPayloadException in Queue.php line 89 If it ised inside broadcast laravel events (which must be delivered into browser) then node.js fails to

Sorting a many to many relation with Laravel Eloquent

余生颓废 提交于 2019-12-25 04:43:33
问题 I do have swatches table, a colors table and a swatch_color pivot table. Relations are set as: public function colors() { return $this->belongsToMany('Color'); } public function swatches() { return $this->belongsToMany('Swatch'); } I have no problem to retrieve the swatches with the color relations $swatches = Swatch::with('colors')->get(); return dd($swatches); Colors is always an array of 5 color objects with hue, R, G, and B attributes. Now I would like to sort the swatches by the R value

Order by Votes in Laravel ORM

我怕爱的太早我们不能终老 提交于 2019-12-25 04:24:17
问题 I have 3 Models... Category, Post, Vote When viewing a category, I am showing an index of all Posts in that category. So I'm doing something like foreach ($category->posts as $post) in my view. The question I have now is how can I order the posts based on the sum of votes they have? I have standard relationships setup, so that a post hasMany votes. 回答1: You can do it either by defining a helper relation on the Post model and sorting the collection after the relation is loaded OR simply by

Laravel Eloquent ORM returnig stdClass instead of actual Model

喜欢而已 提交于 2019-12-25 04:19:40
问题 I'm doing $mymodel = MyModel::where( 'url', $domain )->first(); and this was returning a MyModel object and now, somehow, it is returning a stdClass. What's happening? Is it some update on the laravel? Have I changed something? Thanks 回答1: Found the problem. I did updated the laravel today and it was updating to a dev version. By being dev it could have bugs and it did. I just rollback to version "4.1.22" and it's working fine. 回答2: I ran into the exact same issue yesterday. But just updated