In this step we need facebook app id and secret that way we can get information of other user. so if you don’t have facebook app account then you can create from here : https://developers.facebook.com/apps and after create account you can copy client id and secret. Now you have to set app id, secret and call back url in config file so open config/services.php and .env file then set id and secret this way: config/services.php
Now add addNew() in User model, that method will check if facebook id already exists then it will return object and if not exists then create new user and return user object. so open user model and put bellow code: app/User.php
we need to add new controller and method of facebook auth that method will handle facebook callback url and etc, first put bellow code on your FacebookController.php file. app/Http/Controllers/Auth/FacebookController.php
You know some birds are not meant to be caged, their feathers are just too bright.
File uploads is one of the most important functions on the internet, and we have bigger files nowadays, which means it’s not enough to have simple input fields – we need AJAX and processing file upload “in the background”. Here I will show you a simple example of that in Laravel 5.
Let’s say, we have a simple form to upload the product and many photos for it.
And we want to upload photos and see upload progress immediately, only then submitting the form. For that we will use a jQuery-File-Upload library.
Step 1. Database structure
1 2 3 4 5 6 7 8 9 10 11 12 13
Schema::create('products', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->timestamps(); });
As you can see, field product_photos.product_id is nullable – which means we can upload photos without saving product with them yet. We’ll show later why.
Step 2. Routes and MVC
First, let’s decide our URLs. In routes/web.php we will have this:
Now, let’s download jQuery-File-Upload library and put its /js contents into our /public/js. And then we can use it like this – in the end of our upload_form.blade.php:
To be honest, I’m not a strong front-ender, so the syntax was written according to jQuery-File-Upload library examples. But basically, it works like this:
fileupload() method is attached to input field and takes two important parameters – name=”photos[]” data-url=”/upload”;
Those parameters are passed via AJAX request to /upload URL – meaning UploadController and method uploadSubmit();
uploadSubmit() physically uploads the file, stores information in the database but doesn’t store product_photos.product_id because we don’t have ID yet. After upload it returns JSON with array of file results;
Those results are shown to the user in the file list (filename and size) and also in the hidden field file_ids which stores values from product_photos.id column;
We can upload more files like this, and our files list will grow bigger and bigger. As soon as we hit the main submit – the data will be posted and UploadController method postProduct() will save the data into products DB table, and also assign new product ID to product_photos entries:
Hope is a good thing and maybe the best of things. And no good thing ever dies.
Starting at v5.4.12, Laravel Collections now includes a when method that allows you to perform conditional actions on the items without breaking the chain.
Like all the other Laravel Collection methods this one can have a lot of use cases but one example that comes to mind is being able to filter based on a query string parameter.
To demonstrate that example, let’s pretend we have a list of hosts from the Laravel News Podcast: