本文整理汇总了PHP中Events::checkSlugName方法的典型用法代码示例。如果您正苦于以下问题:PHP Events::checkSlugName方法的具体用法?PHP Events::checkSlugName怎么用?PHP Events::checkSlugName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Events
的用法示例。
在下文中一共展示了Events::checkSlugName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createEvent
public static function createEvent($input)
{
$started_at = empty($input['started_at']) ? 'no' : preg_split("/([\\/: ])/", $input['started_at']);
$ended_at = empty($input['ended_at']) ? 'no' : preg_split("/([\\/: ])/", $input['ended_at']);
$input = array('event_category_id' => $input['event_category_id'], 'city_id' => $input['city_id'], 'email' => $input['email'], 'creator_fname' => $input['creator_fname'], 'creator_lname' => $input['creator_fname'], 'creator_email' => $input['creator_email'], 'name' => $input['name'], 'user_id' => Auth::check() ? Auth::user()->id : '', 'stewardship' => $input['stewardship'], 'description' => $input['description'], 'location' => $input['location'], 'website_url' => $input['website_url'], 'social_media_urls' => $input['social_media_urls'], 'started_at' => $started_at == 'no' ? '' : mktime((int) $started_at[3], (int) $started_at[4], 0, (int) $started_at[0], (int) $started_at[1], (int) $started_at[2]), 'ended_at' => $ended_at == 'no' ? '' : mktime((int) $ended_at[3], (int) $ended_at[4], 0, (int) $ended_at[0], (int) $ended_at[1], (int) $ended_at[2]));
$rules = array('event_category_id' => 'required', 'city_id' => 'required', 'creator_fname' => 'required', 'creator_lname' => 'required', 'creator_email' => 'required|email', 'email' => 'required|email', 'name' => 'required', 'stewardship' => 'required|min:5', 'description' => 'required|min:5', 'location' => 'required', 'started_at' => 'required', 'ended_at' => 'required');
$validator = Validator::make($input, $rules);
if ($validator->fails()) {
return $validator->errors()->all();
} else {
try {
// Mencatat pembuat target sosial
if (Auth::check()) {
$input['user_id'] = Auth::user()->id;
} else {
// Check apakah user ada di database
$check_user = User::where('email', $input['creator_email']);
if ($check_user->count() > 0) {
$input['user_id'] = $check_user->pluck('id');
} else {
// Membuat user baru dengan status draft (status:2)
$post = new User();
$post->firstname = $input['creator_fname'];
$post->lastname = $input['creator_lname'];
$post->email = $input['creator_email'];
$post->status = 2;
$post->save();
$input['user_id'] = $post->id;
}
}
unset($input['creator_fname']);
unset($input['creator_lname']);
unset($input['creator_email']);
$event = new Events();
$event->fill($input);
$event->save();
// digunakan untuk mengambil id user yang belum login
if (!Auth::check()) {
Session::put('update_id', $event->id);
}
// update
$update = Events::find($event->id);
$update->fill(array('slug' => Events::checkSlugName(Str::slug($input['name'])) > 0 ? strtolower(Str::slug($input['name'])) . $event->id : strtolower(Str::slug($input['name']))));
$update->save();
return "ok";
} catch (Exception $e) {
return "no";
}
}
}
示例2: createEvent
public static function createEvent($input)
{
$started_at = empty($input['started_at']) ? 'no' : preg_split("/([\\/: ])/", $input['started_at']);
$ended_at = empty($input['ended_at']) ? 'no' : preg_split("/([\\/: ])/", $input['ended_at']);
$input = array('event_category_id' => $input['event_category_id'], 'city_id' => $input['city_id'], 'email' => $input['email'], 'name' => $input['name'], 'user_id' => Auth::check() ? Auth::user()->id : '', 'stewardship' => $input['stewardship='], 'description' => $input['description'], 'location' => $input['location'], 'website_url' => $input['website_url'], 'social_media_urls' => $input['social_media_urls'], 'started_at' => $started_at == 'no' ? '' : mktime((int) $started_at[3], (int) $started_at[4], 0, (int) $started_at[0], (int) $started_at[1], (int) $started_at[2]), 'ended_at' => $ended_at == 'no' ? '' : mktime((int) $ended_at[3], (int) $ended_at[4], 0, (int) $ended_at[0], (int) $ended_at[1], (int) $ended_at[2]));
$rules = array('event_category_id' => 'required', 'city_id' => 'required', 'name' => 'required', 'stewardship' => 'required|min:5', 'description' => 'required|min:5', 'location' => 'required', 'started_at' => 'required', 'ended_at' => 'required');
$validator = Validator::make($input, $rules);
if ($validator->fails()) {
return $validator->errors()->all();
} else {
try {
$event = new Events();
$event->fill($input);
$event->save();
// digunakan untuk mengambil id user yang belum login
if (!Auth::check()) {
Session::put('update_id', $event->id);
}
// update
$update = Events::find($event->id);
$update->fill(array('slug' => Events::checkSlugName(Str::slug($input['name'])) > 0 ? strtolower(Str::slug($input['name'])) . $event->id : strtolower(Str::slug($input['name']))));
$update->save();
return "ok";
} catch (Exception $e) {
return "no";
}
}
}