0

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();

    }
}
Arkan Kalu
  • 403
  • 2
  • 4
  • 16
  • 1
    Does this answer your question? [PHP parse/syntax errors; and how to solve them](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – apokryfos Jun 03 '20 at 10:03
  • 4
    In your particular case the issue is your try/catch block is outside any function block, which is invalid PHP syntax. – apokryfos Jun 03 '20 at 10:04
  • That solved it, thanks! – Arkan Kalu Jun 03 '20 at 10:35

0 Answers0