Table of Contents
- 1) for our basic CRUD system, we need below database tables
- 2) Now we need Laravel model for this table.
- 3) Creating the app API
- 4) Now we need to create laravel controller 'SampleController.php' inside
- 5) using React Router
- 6) Creating a wildcard route
- 7) Let's create the app.blade.php view file.
- 8) Creating the App component
- 9) open and update resources/js/app.js as below:
- 10) Creating the Header component
- 11) Above we are using bootstrap css framework classes, we need to install bootstrap react package to use this execute below coomand
- 12) For making http request we will use 'axios' package
- 13) Displaying all items
- 14) Now create SampleCreate.js component inside resources/js/components
- 15) Create SampleEdit.js component inside folder 'resources\js\components'
- Conclusion
ReactJS is a declarative, efficient, and flexible JavaScript library for building reusable UI components.
It is an open-source, component-based front end library responsible only for the view layer of the application.
React have lots of features that power the web app. One of it's major feature is virtual DOM . React applications loads faster than any normal web app because of it 's faster virtual DOM loading.
I am React Frontend Developer based in India. Working as a PHP developer since 2009.
I will guide you to create React CRUD with most popular PHP Laravel Framework.
Let's start one by one .
1) for our basic CRUD system, we need below database tables
Below shown it's screenshot 2) Now we need Laravel model for this table.
Create Sample.php inside 'app' folder and put below
3) Creating the app API
We'll start by defining the API endpoints. Open routes/api.php and replace it content with the code below: We are using laravel Restfull API it allow to perform CRUD system on the url
4) Now we need to create laravel controller 'SampleController.php' inside
app\Http\Controllers and put below code
Here, we created functions for fetching all items as well for fetching a single item.
Then for creating new item . 5) using React Router
We'll be using React Router to handle routing in our application. Install it using below command
6) Creating a wildcard route
Wwe need to render a single view file for all our application routes. Open routes/web.php and replace it content with the code below:
We define a wildcard route. An app.blade.php view file will be rendered for all our app routes. This way, we can render our React components from within this view file, and we’ll be able use all the goodies that React has to offer. 7) Let's create the app.blade.php view file.
We’ll create this file directly within the resources/views directory, then paste the following code in it: