DB::table('job_post')->insert(['user_id'=>$user->id,'job_title'=>$data['job_title'],'job_skill'=>$data['skill'],'max_sal'=>$data['max_sal'],'min_sal'=>$data['min_sal'],'job_type'=>$data['job_type'],'shift'=>$data['shift'],'last_date'=>$data['last_date'],'job_image'=>$imagename,'job_description'=>$data['job_description'],'latitude'=>$data['latitude'],'longitude'=>$data['longitude'],'location'=>$data['location']]);
//return redirect()->to('employer/congrats/......here i want id of job_post which i create');
return view('employer/congrats',compact('id','navbar_data'));
答案 0 :(得分:0)
是的,您可以通过insertGetId获取Laravel中最后插入的ID:
$id = DB::table('users')->insertGetId(
array('email' => 'john@example.com', 'votes' => 0)
);
return redirect('employer/congrats',compact('id','navbar_data'));
答案 1 :(得分:0)
您可以尝试这样的事情
DB::table('job_post')->insert([
// ... data to insert e.g. 'user_id' => $user->id,
]);
$id = DB::getPdo()->lastInsertId();
return view('employer.congrats', compact('id','navbar_data'));
或
const array = [
['a', 'b', 'c'],
['d', 'e'],
['f', 'g', 'h', 'i', 'j'],
['k'],
['l'],
['m'],
['n', 'o', 'p'],
['q', 'r', 's'],
['t', 'u', 'v'],
['x']
];
function shuffle(arr) { /* Shuffling algorithm here */ }
shuffle(array);
// Extracts arrays with exactly "count" elements, excluding all elements in "exclude" and starting at "start" in the array
// If no combination was found, return undefined
function takeOut(array, count, start = 0, exclude = []) {
// Base case: Count wasn't reached exactly, abort here
if(count < 0) return;
// Base case: Combination was found, go up
if(count === 0) return [];
// Go over the array to find a matching combination
for(let i = start; i < array.length; i++) {
const current = array[i];
// Skip elements that should be excluded
if(exclude.includes(current)) continue;
// Recursive call: Find more elements so that a group of "count" gets reached
const rest = takeOut(array, count - current.length, i + 1, exclude);
if(!rest) continue; // If this element can't be matched up, go on
return [current, ...rest];
}
}
// Our two teams:
const first = takeOut(array, 5);
const second = takeOut(array, 5, 0, first); // all from the first team can't be in the second one
console.log(first, second);
if(first && second)
console.log("The game can start");
有关更多信息,请查看this博客文章。