Support the ongoing development of Laravel.io →
posted 8 years ago
Eloquent
Last updated 2 years ago.
0

There are a few methods in doing this:

Static method in your model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Users_Model extends Model
{
    //

    protected $table = 'inh';

    public static function login_validate()
	{
      return "Hello!";
    }
}
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Users_Model;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class LoginController extends Controller
{
    public function getLogin() {
      return view('pages.login');
    }

    public function sample(){

    $sample_two =  Users_Model::login_validate();
    echo $sample_two;
    }
}

Resolve the model in the container

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Users_Model extends Model
{
    //

    protected $table = 'inh';

    public function login_validate()
    {
      return "Hello!";
    }
}
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Users_Model;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class LoginController extends Controller
{
    public function getLogin() {
      return view('pages.login');
    }

    public function sample(Users_Model $usersModel){

    $sample_two =  $usersModel->login_validate();
    echo $sample_two;
    }
}
Last updated 8 years ago.
0

I see now. So you need to pass the Name of the Model into the Parameters of my Function? :)

I'll give this a try and give you a fast response. Thank you moinescumihai! :)

0

its not working ..

0

Sign in to participate in this thread!

Eventy

Your banner here too?

esseisan esseisan Joined 24 Jul 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.