Schema specified is not valid. Errors: The relationship was not loaded because the type is not available

The error is a little cryptic, so I’m not sure if this is the reason you’re getting that particular error, but I do know it will cause some error, so you can start by fixing this: What you have is two one-to-many relationships to the same model on one class. That’s not a problem per … Read more

Implementing Zero Or One to Zero Or One relationship in EF Code first by Fluent API

By changing pocos to: public class Order { public int OrderId { get; set; } public virtual Quotation Quotation { get; set; } } public class Quotation { public int QuotationId { get; set; } public virtual Order Order { get; set; } } and using these mapping files: public class OrderMap : EntityTypeConfiguration<Order> { … Read more

Creating API that is fluent

This article explains it much better than I ever could. EDIT, can’t squeeze this in a comment… There are two sides to interfaces, the implementation and the usage. There’s more work to be done on the creation side, I agree with that, however the main benefits can be found on the usage side of things. … Read more

How to select count with Laravel’s fluent query builder?

You can use an array in the select() to define more columns and you can use the DB::raw() there with aliasing it to followers. Should look like this: $query = DB::table(‘category_issue’) ->select(array(‘issues.*’, DB::raw(‘COUNT(issue_subscriptions.issue_id) as followers’))) ->where(‘category_id’, ‘=’, 1) ->join(‘issues’, ‘category_issue.issue_id’, ‘=’, ‘issues.id’) ->left_join(‘issue_subscriptions’, ‘issues.id’, ‘=’, ‘issue_subscriptions.issue_id’) ->group_by(‘issues.id’) ->order_by(‘followers’, ‘desc’) ->get();

How to set every row to the same value with Laravel’s Eloquent/Fluent?

Just to keep this thread current, you can update all rows against an Eloquent model directly using: Model::query()->update([‘confirmed’ => 1]); If you are using something like WHERE Model::where(‘foo’, ‘=’, ‘bar’)->update([‘confirmed’ => 1]) If you want to include soft deleted rows as well Model::query()->withTrashed()->update([‘confirmed’ => 1]);

Laravel – Eloquent or Fluent random row

Laravel >= 5.2: User::inRandomOrder()->get(); or to get the specific number of records // 5 indicates the number of records User::inRandomOrder()->limit(5)->get(); // get one random record User::inRandomOrder()->first(); or using the random method for collections: User::all()->random(); User::all()->random(10); // The amount of items you wish to receive Laravel 4.2.7 – 5.1: User::orderByRaw(“RAND()”)->get(); Laravel 4.0 – 4.2.6: User::orderBy(DB::raw(‘RAND()’))->get(); Laravel … Read more