i am trying to create a something like below, in my Laravel 5.1 project within helper.php.
$result = App\Pages::where('id', $id)->where('active', 1)->first();
here is how my helper.php looks like:
<?php
namespace App\Helpers;
use App;
class Helper
{
public static function checkSlug($subject, $id, $inputSlug = null){
$result = App\$subject::where('id', $id)->where('active', 1)->first();
return $result;
}
}
?>
My Helper class seems working fine. But i am stuck in this line App\$subject::where('id', $id)->where('active', 1)->first();
. When i pass the variable $subject
i get this below error:
parse error, expecting `"identifier (T_STRING)"'
And here is how i am using my helper method in my view
{{Helper::checkSlug('Pages', $page->id)}}
Now when i am trying to access my Model using App\$subject
its not allow. I guess.
Any suggestions will be helpful. Thank you!