We are creating a controller that will fetch all data of table.
×
Create Controller For Fetch Table All Data
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Query_Controller extends Controller
{
public function index()
{
$data = DB::table('employee')->get();
echo "<pre>";
print_r($data->toArray());
}
}
We creating a controller that will fetch or get data from table where address is india.
×
Create Controller for Query with Where Clause
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Query_Controller extends Controller
{
public function index()
{
$data = DB::table('employee')->where('address', 'india')->get();
echo "<pre>";
print_r($data->toArray());
}
}
We creating a controller that will return string data.
×
Create Controller for Return String
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class Home_Controller extends Controller
{
public function index($value='')
{
return "Wellcome to Home Controller <br>Value is :".$value;
}
public function show($value='')
{
return "Wellcome to Home Controller <br>Value is :".$value;
}
public function edit($value='')
{
return "Wellcome to Home Controller <br>Value is :".$value;
}
}
We creating a controller that will load view with data
×
Create Controller for View Load
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class View_Load_Controller extends Controller
{
public function index($value='')
{
return view('load_view_page')->with(['value'=>$value]);
}
}
We creating a resource controller that will do create some important methods automatically.
×
Create Resource Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class Resource_Controller extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}