I want to have specific properties available for use within all my methods without having to replicate the code in each and every method. So.. I'm thinking perhaps putting the code into the constructor is the way to go.
It might not be as it is not working as expected. PHPStorm is has greyed out the $contractor variable within the constructor telling me that it is not in use anywhere. Yet the $contractor variable within the Index method is not greyed out. Nevertheless, I do not get the $contractor variable for use in Index().
Many thanks for your thoughts, and corrections !
class AccountController extends Controller
{
protected $contractor;
protected $email;
protected $id;
public function __construct(Contractor $contractor,Auth $id){
$this->id=Auth::id();
$user = User::find($this->id);
$contractor = Contractor::where('email', '=', $user->email)->get();
}
public function index($contractor) // THIS DOES NOT WORK
{
return View('contractor_portal/account_show',compact('contractor' ));
}
}