start by watching the Laravel from scratch video series here.
What you need to know is far too much to write in a forum response.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Good evening, hello everyone. Let me start by saying that I'm new and I'm just starting to program with Laravel and programming in general.
I'm making an HR portal with Laravel and a ready-made theme.
I just want to know one thing, how do I get data from a table via a controller or middleware, into a blade sheet? I'll explain, I have to recall the data from the customer card, the table is done, but I don't know how to recall the name of the employee's department. I'll show you the controller, the model and the middleware:
This i s a controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Department;
use Illuminate\Support\Facades\DB;
class DepartmentsController extends Controller
{
public function createDepartment(Request $request) // Retrives all the Holidays and Sends to the Blade
{
$user=new Department;
$user->department_name=$request->input('department_name');
$user->admin_user_id=auth()->user()->id;
$user->save();
return response()->json(['message' => 'Employee added successfully']);
}
public static function getAllDepartments()
{
$data = DB::table('departments')
->select('departments.*')
->orderBy('departments.created_at', 'DESC')
->get();
return $data;
}
public static function getMyDepartments()
{
$data = DB::table('departments')
->select('departments.*')
->where('admin_user_id',auth()->user()->id)
->orderBy('departments.created_at', 'DESC')
->get();
return $data;
}
}
This is a model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Department extends Model
{
use HasFactory;
protected $table = 'departments';
protected $fillable = [
'department_name',
'admin_user_id',
];
}
How do I insert the department_name onto a blade sheet?
Please or to participate in this conversation.