In this post, we gonna create custom functions and load it in the Laravel project. These functions can be accessible all over the project. Loading custom helper functions in Laravel is pretty straightforward. Let’s […]
Eloquent – A better way to increment or decrements an int
Laravel has in-built increment() and decrement() functions to increase or decrease a value of the column, by 1 or with the given number. Below are the examples:
1 |
User::find($user_id)->increment('post_count'); |
How to Upload, download, remove Files to Amazon S3 Using Laravel
Create a controller called UploadController.php with following code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Storage; class UploadController extends Controller { public function index() { $files = Storage::disk('s3')->files('files'); $data = []; foreach($files as $file) { $data[] = [ 'name' => basename($file), 'downloadUrl' => url('/download/'.base64_encode($file)), 'removeUrl' => url('/remove/'.base64_encode($file)), ]; } return view('upload', ['files' => $data]); } public function store(Request $request) { $this->validate($request, [ 'file' => 'required|max:2048' ]); if ($request->hasFile('file')) { $file = $request->file('file'); $name = time() . $file->getClientOriginalName(); $filePath = 'files/' . $name; Storage::disk('s3')->put($filePath, file_get_contents($file)); } return back()->withSuccess('File uploaded successfully'); } public function destroy($file) { $file = base64_decode($file); Storage::disk('s3')->delete($file); return back()->withSuccess('File was deleted successfully'); } public function download($file) { $file = base64_decode($file); $name = basename($file); Storage::disk('s3')->download($file, $name); return back()->withSuccess('File downloaded successfully'); } } |
How to use Datatables in Laravel 5.8
In this tutorial, I will show you how to use the Datatables in the Laravel based project withyajra/laravel-datatables-oracle package. For this tutorial, we gonna use Laravel 5.8 version but the Datatable package usage […]
How to create RESTful API in Laravel 5.7
In this tutorial, I will show you creating RESTful apis using Laravel 5.7 php framework. We gonna use the Laravel’s API resources to build RESTful APIs. Laravel’s API Resource class is a way to transform data […]
Laravel Eloquent Increments and Decrements value
In this post, I would like to show you the hidden and useful functions of Laravel’s Eloquent ORM to Increment and Decrement value of the fields in the database column. In my recent project, I used increment() and […]
Laravel 5.6 Socialite Bitbucket Login
In this tutorial, we’re going to explain how to integrate Bitbucket login in Laravel based application using Socialite. The Socialite is Laravel’s official package, which is making is easy to authenticate with […]
Laravel 5.6 Socialite GitHub Login
In this tutorial, we’re going to explain how to integrate GitHub login in Laravel based application using Socialite. The Socialite is Laravel’s official package, which is making is easy to authenticate with external […]
Laravel 5.6 Socialite LinkedIn Login
In this tutorial, we’re going to explain how to integrate LinkedIn login in Laravel based application using Socialite. The Socialite is Laravel’s official package, which is making is easy to authenticate with external […]
Laravel 5.6 Socialite Google Login
In this tutorial, we’re going to explain how to integrate Google login in Laravel based application using Socialite. The Socialite is Laravel’s official package, which is making is easy to authenticate with external […]