Here's my standard setup I use to backup data to my Dropbox account. This post is also made as a note for my self. So I don't forget in the furture.
Open file: DropboxServiceProvider.php and paste below.
Laravel Dropbox. Back to Open Source. Introduction Application Register Install Usage Middleware Files Introduction Application Register. We are a welcoming place for everyone, and we do our best to make sure all people feel supported and connected at work. A big part of that effort is our support for members and allies of internal groups like Asians at Dropbox, BlackDropboxers, Latinx, Pridebox (LGBTQ), Vets at Dropbox, Women at Dropbox, ATX Diversity (based in Austin, Texas) and the Dropbox Empowerment Network (based in Dublin. He utilizes the Laravel 5 Backup Package and Flysystem then shows you the steps involved in creating a Dropbox API app and utilizing Laravel Scheduler. Barnes Eric is the creator of Laravel News and has been covering Laravel since 2012.
In boot function paste.
Now open app.php in config to register Dropbox service (In providers)
Next open filesystem.php and add.
Step 2: Install laravel-backup from Spatie
Open database.php (Code below is for local-test and on Windows 10. Uncomment dump_binary_path for production site).
Now open backup.php and adjust settings for your own configurations. Below is my setup.
In order to make above work we have to enter some information in .env file.
Schedule cron job to run backup. (My backup runs every sunday)
Step 3: Dropbox token
First you need to login on your Dropbox account. Click on the Create app button. Next step, you will be asked for choosing an API. Choose Scoped access. In the type of access choose App folder and give the name to your app/folder.
- Create an account on Dropbox / 2. Go to App console .
After creating an app, You'll be redirected to a page where you can generate access token. After clicking Generate, copy token value and define the constant DROPBOX_AUTH_TOKEN in the .env file.
That's it. We're done with the required setup to backup our Laravel project to Dropbox. Let's try to run our first backup. Open terminal in your project root dir and run command.
That's it 👏
While building admin/CMS or just a form on your site you might need to build a dropdown (select) list with values read from database. It is very elegant to do this with Laravel’s Eloquent. (For the sake of this post let’s assume that you want to read values from the database and not from some array stored in a class or somewhere else.)
Let’s suppose the database table is called “countries” and is already populated (You can get one here). It contains, you guessed it, a list of country names, which you would like to display in a HTML dropbox list.
First, create a model named “Country.php” (you can use artisan, excellent Laravel 4 generators or create it manually. Keep in mind that the model name is singular (Country) and the database table is plural (Countries).
In your controller add:
Simple isn’t it? This will return an array of values like “ => Afghanistan  => Aland Islands”… (We are assuming that database field name containing country names is “short_name”).
Note: Personally I like Eloquent but in case you do not want to use Eloquent or/and do not want to have an empty Country.php model lying there just so you can populate drop-down then you can use Laravel’s Fluent Database Query Builder:
Ok, now let’s send this to view with
In above case I am sending
$country_options to admin view that is used to create customers.
In the view you display it like this:
That is all it takes to have a functioning drop-down select box. As you can see we are using Laravel Blade template engine and Form class. With
Input::old('country')) we re-populate it with old values (for example after the form is submitted and there are some errors)
Laravel Dropbox Api
How to combine more fields with concat
In another case (for “customers”) I needed to combine two table fields into one and then populate the drop down with it: customers “first_name” + “last_name” should be “first_name last_name”. You can do this by combining Fluent Query Builder with Eloquent:
Laravel Drop Column If Exists
As you can see we are mixing Eloquent and DB:raw method.
Laravel Drop Table
Note: If you only want to use Laravel’s Database Query Builder then you can do this:
How to add default option to dropdown list
Sometimes we want to have some default value that gives us some instructions what to do (“Please select a country,…”) with the dropdown or maybe even some default “non-value” (in case user doesn’t want to select anything). The easiest way to do this is to add
array(' => 'Select One') + so our code looks like this (few examples with the code in this post):
Keep in mind that you will have to add some validation (jQuery, Laravel’s own validation etc) in case user leaves the default option (in example above we leave the value as empty but you can set it to anything you want).
I really love Laravel 4, it makes developing so much fun and simple.