📲 Download Our Apps

EMI Calculator

Download EMI Calculator

SOA Games

Download SOA Games

SOA Technology App

Download SOA Technology

BMI Checker

Download BMI Checker

Task Jira

Download Task Jira

Laughing Adda

Download Laughing Adda

📅 हिंदी कैलेंडर ऐप डाउनलोड करें

Download Shubhcalendar App

Complete Laravel installation and API guide

How to install Laravel using composer

composer create-project laravel/laravel example-app

cd example-app

php artisan serve

Create View in Laravel

<!-- View stored in resources/views/home.blade.php -->

<html>
    <body>
        <h1>My Home Page {{ $name }}</h1>
    </body>
</html>


<!-- Route stored in routes/web.php -->


Route::get('/', function () {
    return view('greeting', ['name' => 'James']);
});

Create model, controller and view in Laravel

Step 1: Create model and controller

php artisan make:controller HomeController --resource --model=Home

Step 2: Create View in Laravel



<!-- View stored in resources/views/home.blade.php -->

<html>
    <body>
        <h1>My Home Page {{ $name }}</h1>
    </body>
</html>

Step 3: call controller using route and display view




<!-- Route stored in routes/web.php -->

Route::get('/home', 'App\Http\Controllers\HomeController@index');

or 

Route::get('/home', 'HomeController@index');

Note: changing the RouteServiceProvider.php file in App/Providers/ path by uncommenting the code.

protected $namespace = ‘App\Http\Controllers’;

Create and Rest Api in Laravel

php artisan make:controller ApiController

You will find a new file named ApiController.php in the app\http\controllers directory. Next, we can add the following methods:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ApiController extends Controller
{
    public function sendResponse($result, $message)
  {
    $response = [
          'success' => true,
          'data'    => $result,
          'message' => $message,
      ];
   return response()->json($response, 200);
  }

  /**
     * return error response.
     *
     * @return \Illuminate\Http\Response
     */
    public function sendError($error, $errorMessages = [], $code = 404)
    {
    	$response = [
            'success' => false,
            'message' => $error,
        ];


        if(!empty($errorMessages)){
            $response['data'] = $errorMessages;
        }


        return response()->json($response, $code);
    }


//
    public function getList() {

      /*  $test = Test::get()->toJson(JSON_PRETTY_PRINT);
        return response($tests, 200);*/

      /*  return response()->json([
            "message" => "student record created"
        ], 201);*/

$data= array();     
          $data = DB::connection('default')->table('users')->where('id',$id)->get();
        return $this->sendResponse($data, 'Successfully');
        
      }
}

Proceed to the routes directory and open the api.php file and create the endpoints that will reference the methods created earlier in the ApiController

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

<!-- Route stored in routes/api.php -->

Route::get('getList', 'App\Http\Controllers\ApiController@getList');

or

Route::get('getList', 'ApiController@getList');

Test Api using Postman

Useful command for Laravel

composer dumpautoload

php artisan cache:clear

php artisan config:clear

php artisan view:clear

command php artisan list

 make:channel         Create a new channel class
  make:command         Create a new Artisan command
  make:controller      Create a new controller class
  make:event           Create a new event class
  make:exception       Create a new custom exception class
  make:factory         Create a new model factory
  make:job             Create a new job class
  make:listener        Create a new event listener class
  make:mail            Create a new email class
  make:middleware      Create a new middleware class
  make:migration       Create a new migration file
  make:model           Create a new Eloquent model class
  make:notification    Create a new notification class
  make:observer        Create a new observer class
  make:policy          Create a new policy class
  make:provider        Create a new service provider class
  make:request         Create a new form request class
  make:resource        Create a new resource
  make:rule            Create a new validation rule
  make:seeder          Create a new seeder class
  make:test            Create a new test class



Leave a Reply

AI Spiritual Tools & Interactive Experiences

Explore powerful AI-driven tools for daily guidance, spirituality, fun quizzes, and self-discovery.

Today’s Quote

Get inspiring daily quotes powered by AI to motivate and guide your day.

Explore Now

AI Tarot Card Reader

Reveal insights about your future, love, and career with AI tarot readings.

Read Tarot

Love Match Calculator

Check compatibility and love predictions using AI-based analysis.

Check Match

Fortune Cookie

Open an AI fortune cookie and receive wisdom, luck, and fun messages.

Open Cookie

Quiz Categories

Engage with knowledge-based and fun quizzes across multiple categories.

Start Quiz

Panchang Calendar

View daily Panchang, auspicious timings, tithi, nakshatra, and festivals.

View Panchang

Online Numerology

Discover your destiny number, life path, and numerology predictions.

Calculate Now

Spiritual Feeds

Stay connected with spiritual thoughts, mantras, and divine content.

View Feeds

Quiz Hub

Attempt trending quizzes on GK, spirituality, festivals, and more.

Explore Quizzes