To get the company id and user_id from the company table, you can use the Eloquent ORM provided by Laravel. Assuming you have a Company model and a User model, you can retrieve the required data using the following steps:
- Import the necessary models at the top of your file:
use App\Models\Company;
use App\Models\User;
- Inside the
jobStoremethod, you can retrieve the company id and user_id using thefindmethod on the respective models:
public function jobStore(JobPostRequest $request)
{
$company = Company::find($company_id);
$user = User::find($user_id);
// Rest of your code...
}
- Once you have retrieved the company and user, you can access their respective ids using the
idproperty:
$company_id = $company->id;
$user_id = $user->id;
- Now you can use these values to create the job:
Job::create([
'user_id' => $user_id,
'company_id' => $company_id,
'title' => request('title'),
]);
return redirect()->back()->with('success', 'Job posted Successfully.');
Make sure to replace App\Models\Company and App\Models\User with the actual namespaces of your models. Also, ensure that the $company_id and $user_id variables are properly assigned before using them in the create method.
Remember to validate and sanitize the input data before using it in your code to prevent any security vulnerabilities.