Answers for "call model laravel"

PHP
2

call model function in controller laravel

$model = new Model;
$model->func();
__________________________________
  or 
Model::func() // this function must be static to call it staticly ..
Posted by: Guest on June-22-2021
0

Using or calling method from Model in Laravel View

// Model Employee.php
use Illuminate\Support\Facades\DB;
public function ages($employee_id)
{
  	$currentYear = date("Y");
  
    $query = DB::table('employees')->where('id', $employee_id)->value('date_of_birth');
    return $currentYear - $query;
}

// EmployeeController.php
use App\Models\Employees;
public function printEmployeeDetails($employee_id)
{
    $data = [
        'employee' => new Employee(),
      	'employee_id' => $employee_id,
    ];

    return view('admin/employee/print-employee-details', $data);
}

// View
$employee->ages($employee_id)
Posted by: Guest on October-24-2021

Code answers related to "call model laravel"

Browse Popular Code Answers by Language