Ukieweb

Diary | Laravel 5

I write what I learn here

Laravel Soft Delete Feature

Sometimes you want to delete a record from your application but still have it in your database in case you want to refer to it in the future. How do you achieve this with ease?

Laravel provides a** Soft Deleting feature** using **Eloquent **that is effective and easy to implement. On high level, a deleted_at column that is _nullable _is included in your table and is updated when a user deletes a record. This feature is useful in tracking the records that are getting deleted because …

Read More

Creating different versions of Laravel 5 application

Laravel versions have been changing very often. At the time of writing this article the current version is 5.5. The default command for creating a Laravel project laravel new projectName uses the latest version of Laravel. The need for creating a project using previous versions of Laravel becomes key especially when you do not want to upgrade other installations such as PHP 5.6.4to at least PHP 7.0 if you want to use Laravel 5.5. …

Read More

Aggregate Functions In Laravel SQL

Task: Get all users and their contribution total. Every contribution is stored as a row in _contributions _table. Tables:

  1. Contributions- stores user contributions
  2. Users- stores user details

Query: $contributions= DB::table('contributions') ->leftJoin('users', 'users.id', '=', 'contributions.user_id') ->select(DB::raw('SUM(amount) as balance'),'name', 'user_id', 'created_by', 'contribution_date', …

Read More