I am trying to write try/catch for my query in Laravel but instead i get this error: Parse error: syntax error, unexpected 'try' (T_TRY), expecting function (T_FUNCTION)
Please view my code below. Any help is greatly appreciated.
<?php
use Exception;
namespace App\Models;
use DB;
use Illuminate\Database\Eloquent\Model;
class UserModel extends Model
{
//
public function loginmodel($email,$password){
$query=DB::select("SELECT * FROM users where email=? and password=?",[$email,$password]);
return $query;
}
try {
loginmodel();
}catch(\Exception $e){
return $e->getMessage();
}
}