I'm creating Models dinamically
Do you know if it is possible to change $casts array at fly?
My DynamicModel
class DynamicModel extends Model
{
protected static $_table;
protected static $_rules;
protected $casts=[];
public $timestamps = true;...
I have a small project, database tables contain max. 30 records ...
Running a SELECT count (*) query directly in the database is a query of less than 1 millisecond.
However, in the console (Clockwork) I see completely different times that come crazy...
Dynamic Model means the table and the attributes are Dynamic,
I tried something like this:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Assets extends Model {
public function __construct($attributes = []) {
paren...
I am working on an existing site developed using plain PHP and have started developing a section of the site using Laravel. I am new to Larvel and it's concepts and have some questions.
I only have App/Users.php class in my app at the moment but ther...
I have 2 tables test and goals. One goal has many tests. I would like to fetch data like below.
$tests = test::with('goals')
->where('Goal_id', $goal_id)
->select('test.id as id','goals.Goal_id as goal_id','test....
I'm trying to decrement like this on related hasOne trashed item but it throws me an error.
$review->category->decrement('total_reviews');
The error:
Call to a member function decrement() on null
Can I decrement on related model which is tras...
I have three tables foo, bar and lorem. They are connected to each other with Many-To-Many relationships.
How can I efficiently get all entries of lorem where foo.id is 123, both directly and through bar (without duplicates) ?
Schema:
Foo -> Lorem...
I have orders table:- id, price,
another table:- order_products:- order_id.product_id,
another table:- products:- id,name.
I need to fetch all the product with a name based on order.
using ORM
thanks...
Hi, I want to ask the community if know about a better pack than this one to make searches on my
search bar
https://github.com/protonemedia/laravel-cross-eloquent-search
this is great I am using it and it is a very good pack but I want to know if th...
I have three Products that can be purchased. I have a model for each of the products. Product1, Product2, Product3. I realize most people would say that I should have a generalized Product but that is not the way I want to do it. These are the only 3...
When I try to use my model it gives me the follwowing error:
Class 'App\Http\Controllers\App\Question' not found
Model Code:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Question extends Model
{
/**
* The table associa...
Hello community,
I have a a model that is called "course" and course has 7 rows.
Let us say they are all boolean except of one.
Now I want to insert rows via DB::Seeder for example.
These rows should cover all the possible outcomes like
The...
I have two tables Foo and Bar linked by ManyToMany relationship.
Is there a better way to to get all foos that have bar_id equal to 123 that this ?
Foo::whereHas('bars', function ($q) { $q->where('id', 123); } )->get();...
Laravel relationship not working.
I have the following models set up:
Video Course Section
class VideoCourseSection extends Model
{
use HasFactory;
public function video_course(){
return $this->belongsTo('App\Models\VideoCourse');...
I want to display related item which is in same category.
Here is my 3 table structure
food item table
:
"food_item_id",
"name" ,
"image" ,
food item category table :
"food_item_category_id"
"name"...
So in mysql a null column comparison like column = NULL will never return true. How about when you are using eloquent? Is ->whereNull('column') equivalent to doing ->where('column', null)?...
Hi I'm struggling to get related model with eager loading and dynamic owner key
If it is not eager loading works fine but i want to make it eager
Is it possible to eager load with dynamic owner key ? Below is what I've done
I'm using Laravel6
Model...
I have this in a controller:
$countries = Country::all();
return view('countries.index', compact('countries'));
I have this variable {{ $countries }} in blade
that render this:
[{"id":1,"code":"CZ","name":&quo...
Hi,
what im trying: display images in view that are provided from database (database has column with path to images stored in storage)
When i check what data i get when accessing from database:
return Cars::all();
i get:
make_image":"stora...
There is a One to Many relationship between Post and Topic models.
Post Model:
public function topic()
{
return $this->belongsTo(Topic::class);
}
public function scopePublished($query)
{
return $query->where...
Having some issues understanding:
https://laravel.com/docs/8.x/pagination#appending-query-string-values
Steps to reproduce
You see a post you like on the main page and click on the title
An error is shown:
Undefined variable: posts in Posts.Index
T...
Hi
i have wallet table and user table (with one to one relationship)
Wallet table has below columns
id
amount
user_id
User table has below Columns
id
name
last_name
so when i want to update wallet table there is any eloquent way to update old valu...
Hi I am wondering how many SQL-Queries are generated, when I map over a collections has many dependencies.
Imagine following:
Model Thing hasMany Foo;
Model Foo has One Bar;
Model Bar hasMany Foo;
When I now make the following statement:
Thing::fir...
I have products, reviews that are related to one product and images that are related to one review .
In case I delete the product, I want to delete product image and all related images for each review from the folders.
The images of each reviews are...
Hello, in my database I have a table "profiles" with a field "info" structured in this way:
{ "skills": ["Organizzazione aziendale", "Sales Manager", "Linguistica"], "interests": [...
Hi, I was hoping to get some advice on this innocuous piece of eloquent :
$users = User::with(['usersSubscriptionFeesCollection' => function ($q) use ($value) {
$q->where('settled','=','0');
}])
->...
Hi! I wrote this code and works but... instead of return the model instance returns just an array
$training = Training::create([
'routine_id' => $routine->id,
'user_id' => auth()->id(),
'accepted_at' => now(),
]);
After create i tr...
I've just finished watching the final project videos in the 'Laravel from scratch' series where Jeffrey builds a Twitter clone. In these videos he builds the functionality to like tweets by building a Like model. The Tweet and User models then have a...
I want to display all food_item_category name in view which is belongs to food item
Here is my 3table informations
food item table column: "food_item_id", "name" , "image"
food item category table column: "food...
There is a belongsToMany relationship between Post and Topic models.
Post Model:
public function topics()
{
return $this->belongsToMany(Topic::class)->withTimestamps();
}
Topic Model:
public function posts()
{...
Hiya, casts!
I've recently been trying to figure out why my eloquent->merge removes an item?
$value['city'] = 'København';
$advertisements = App\Advertisement::whereHas('property', function ($q) use ($value) {
return $q->where('city', 'LI...
I have an enum type, so when the model access the enum with blade, I have the __() function on the accessor, this makes the translation of the enum automatically and avoid having special case codes (as it should). However this messes up with the api...
I noticed that when I eager load the Posts with comments it makes an interesting query using WHERE IN. But SQL has parameter limit of 65535 (at least my old Postgres server does).
So what happens when we try to query for 100k rows and eager load a re...