How to get public directory?

Use public_path() For reference: // Path to the project’s root folder echo base_path(); // Path to the ‘app’ folder echo app_path(); // Path to the ‘public’ folder echo public_path(); // Path to the ‘storage’ folder echo storage_path(); // Path to the ‘storage/app’ folder echo storage_path(‘app’);

A JOIN With Additional Conditions Using Query Builder or Eloquent

$results = DB::table(‘rooms’) ->distinct() ->leftJoin(‘bookings’, function($join) { $join->on(‘rooms.id’, ‘=’, ‘bookings.room_type_id’); $join->on(‘arrival’,’>=’,DB::raw(“‘2012-05-01′”)); $join->on(‘arrival’,'<=’,DB::raw(“‘2012-05-10′”)); $join->on(‘departure’,’>=’,DB::raw(“‘2012-05-01′”)); $join->on(‘departure’,'<=’,DB::raw(“‘2012-05-10′”)); }) ->where(‘bookings.room_type_id’, ‘=’, NULL) ->get(); Not quite sure if the between clause can be added to the join in laravel. Notes: DB::raw() instructs Laravel not to put back quotes. By passing a closure to join methods you can add more join … Read more

Laravel. Use scope() in models with relation

You can do it inline: $categories = Category::with([‘posts’ => function ($q) { $q->published(); }])->get(); You can also define a relation: public function postsPublished() { return $this->hasMany(‘Post’)->published(); // or this way: // return $this->posts()->published(); } and then: //all posts $category->posts; // published only $category->postsPublished; // eager loading $categories->with(‘postsPublished’)->get();

Managing relationships in Laravel, adhering to the repository pattern

I am finishing up a large project using Laravel 4 and had to answer all of the questions you are asking right now. After reading all of the available Laravel books over at Leanpub, and tons of Googling, I came up with the following structure. One Eloquent Model class per datable table One Repository class … Read more

Dropping column with foreign key Laravel error: General error: 1025 Error on rename

You can use this: Schema::table(‘despatch_discrepancies’, function (Blueprint $table) { $table->dropForeign([‘pick_detail_id’]); $table->dropColumn(‘pick_detail_id’); }); If you take a peak at dropForeign source, it will build the foreign key index name for you if you pass the column name as an array.

Laravel blank white screen

Apache Does this answer describe or help your situation? Upgrading to Apache 2.4 come with some changes in Apache configuration. Laravel Are you checking Laravel’s logs or Apache’s logs? Since upgrading to Laravel 4.1, I’ve had white screen “errors” (WSOD) when the application could not write to the log location. I’ve always solved this by … Read more

How to select from subquery using Laravel Query Builder?

In addition to @delmadord’s answer and your comments: Currently there is no method to create subquery in FROM clause, so you need to manually use raw statement, then, if necessary, you will merge all the bindings: $sub = Abc::where(..)->groupBy(..); // Eloquent Builder instance $count = DB::table( DB::raw(“({$sub->toSql()}) as sub”) ) ->mergeBindings($sub->getQuery()) // you need to … Read more