Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Chemoti's avatar

recall data in a blade

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?

0 likes
9 replies
Snapey's avatar

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.

1 like
jlrdw's avatar

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.

Those two statements don't go together yet, not without much needed training / learning.

Like the first answer, get some training first. I even suggest starting with the basic php course.

By the way the courses mentioned are free.

1 like
Chemoti's avatar

instead, I suggest doing a refresher on good manners for both of you. What do I still need to know? which middlewares are used for communication between table and controller? that models define the data to be fetched from a database? that the routes indicate the visible path of the file? that to create a route or a controller you use php artisan make and that on the other hand, artisan is the "middleware" for creating composer for Laravel? that the tables are created with migrations and that you don't use my sql (where both of you are doormats compared to me) but instead use the migrations written in Eloquente. Do one thing before replying, both of you are fucking frustrated, read the post better and then reply you idiots!!!

jlrdw's avatar

@chemoti if as you say you are new to programming, in my opinion you are not ready to write an HR application.

Like I said in another reply:

most trades are four year apprenticeship programs, not one week.

If you can call us idiots then you should already know how to call a view in laravel.

Also just my opinion.

Chemoti's avatar

@jlrdw It's just your opinion and if it's not constructive DO NOT RESPOND!!!! do you know what common sense means? I'm curious to know how you learned to approach Laravel if someone has never shown you the right method!!!! so be less of an idiot!!!

jeffallen's avatar

Are you wanting to know how to pass the data to a view or how to display it? Your controller code is missing in your question.

Chemoti's avatar

sorry, I did but I didn't put the ````

Please or to participate in this conversation.