In this tutorial, we will walk you through the process of creating a Google Drive clone using Laravel and Vue.js. We will cover everything from setting up your development environment to creating the frontend and backend components of the application.
Step 1: Setting up your development environment
Before we can start coding our Google Drive clone, we need to set up our development environment. To do this, you will need to have Laravel and Vue.js installed on your machine.
To install Laravel, you can follow the official documentation at https://laravel.com/docs/8.x/installation. Laravel requires PHP and Composer to be installed on your machine. Once you have Laravel installed, you can create a new Laravel project by running the following command:
laravel new drive-clone
Next, you will need to install Vue.js. You can do this by running the following command:
npm install -g @vue/cli
After installing Vue.js, you can create a new Vue.js project inside your Laravel project by running the following command:
vue create frontend
Step 2: Creating the backend
Now that we have our development environment set up, we can start creating the backend of our Google Drive clone. We will be using Laravel to create the backend API for our application.
First, let’s create a new controller for handling file uploads. You can do this by running the following command:
php artisan make:controller FileController
Next, open the newly created FileController.php
file in the app/Http/Controllers
directory. Inside the controller, create a method for uploading files:
public function uploadFile(Request $request)
{
$file = $request->file('file');
$fileName = $file->getClientOriginalName();
$file->storeAs('uploads', $fileName);
return response()->json(['message' => 'File uploaded successfully']);
}
Now, let’s create a route for handling file uploads. Open the routes/api.php
file and add the following route:
Route::post('upload', 'FileController@uploadFile');
Step 3: Creating the frontend
With the backend setup, we can now move on to creating the frontend of our Google Drive clone. We will be using Vue.js to create the frontend components of our application.
First, let’s create a new component for uploading files. Inside the frontend/src/components
directory, create a new file called UploadFile.vue
and add the following code:
<template>
<div>
<input type="file" @change="uploadFile">
</div>
</template>
<script>
export default {
methods: {
uploadFile(e) {
let file = e.target.files[0];
let formData = new FormData();
formData.append('file', file);
axios.post('/api/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
}).then(response => {
console.log(response.data.message);
}).catch(error => {
console.log(error.response.data.message);
});
}
}
}
</script>
Next, let’s include our UploadFile
component in the App.vue
file. Update the App.vue
file as follows:
<template>
<div>
<upload-file></upload-file>
</div>
</template>
<script>
import UploadFile from './components/UploadFile';
export default {
components: {
UploadFile
}
}
</script>
Step 4: Testing the application
Now that we have created both the backend and frontend components of our Google Drive clone, we can test the application. Start by running the Laravel server:
php artisan serve
Next, navigate to the frontend
directory and run the Vue.js development server:
npm run serve
Now, open your browser and navigate to http://localhost:8080
to see the frontend of your Google Drive clone. Try uploading a file using the UploadFile
component and check the backend to see if the file was successfully uploaded.
Congratulations! You have successfully created a Google Drive clone using Laravel and Vue.js. You can now customize the application further by adding features such as file sharing, folder organization, and user authentication. Happy coding!
If you are using Laravel 11, in 1:29:13, you need to change the returned route in "store" method of RegisteredUserController into:
return redirect(route('myFiles', absolute: false));
Can you turn on subtitles?
Hi zura, can you make a vlog about your journey as web developer. You also can make vlog about your current job
Does this sync files and folders directly or I need to upload everytime?
Use Laravel Herd for setup and save 30 minutes
sorry i'm not good at hearing, I can understand but it would be better if there is a subtitle or caption enabled
ok.. after 3 days i've been searching on google and laravel 11 documentation because im using laravel 11 for this tutorial, and for validation folder already exist, in 2:25:00 this tutorial, at this time, is always cant validated the "name" folder, and then i tried to deleted this script ->where('parent_id', $this->parent_id) in StoreFolderRequest.php file or.. you can add this script like this one below
return array_merge(parent::rules(),
[
'name' => [
'required',
'unique:files',
Rule::unique(File::class, 'name')
->where('created_by', Auth::id())
->where('parent_id', $this->input('parent_id'))
->whereNull('deleted_at')
]
]
);
now it works like a charm, btw thanks alot Zura for this tutorial, You are the best
should i learn vue.js first befor getting in this project ?
i understood nothing, sad
5:31:35
You can take this course without know Laravel or Vue? or there is need of having previous knowledge?
I really appreciate all the hard work of creating such an incredible project, but it would be interesting to specify in somewhere visible that this is for Laravel 10. Trying to replicate this project in version 11 could be difficult for beginners since they will run into random issues and incompatibilities
no subtitle
can i do this course to learn laravel? or should i come with eariler knowledge about laravel?
Hi guys, I just came across this awesome course, but before I start digging in, does the course implement opening uploaded folder?
I have finished this course.
Who else complete this full course??
📌Latest 39:15
can i use Apache with Laravel sail ?
Getting this issue in headlessui MenuItem : CreateNewDropdown.vue:21 Uncaught (in promise) TypeError: Cannot destructure property 'active' of 'undefined' as it is undefined.
You've installed windows installer on Ubuntu running on Windows?