本文整理汇总了PHP中Branch::whereHas方法的典型用法代码示例。如果您正苦于以下问题:PHP Branch::whereHas方法的具体用法?PHP Branch::whereHas怎么用?PHP Branch::whereHas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Branch
的用法示例。
在下文中一共展示了Branch::whereHas方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postGuestPostsCountry
public function postGuestPostsCountry()
{
//verify the user input and create account
$validator = Validator::make(Input::all(), array('Type' => 'required|in:Notice,Eventsq,Job,Offer', 'Title' => 'required|max:40', 'Description' => 'required', 'Name' => 'required|max:120', 'Email' => 'required|email|max:60', 'Pic' => 'image|max:3000', 'Country' => 'required'));
if ($validator->fails()) {
return Redirect::route('advanced_squeeb-get')->withErrors($validator)->withInput()->with('global', 'Sorry!! Your Squeeb was not posted, please retry.');
} else {
$type = Input::get('Type');
$title = Input::get('Title');
$description = Input::get('Description');
$description = $this->MakeUrls($description);
$squeeb = substr(strip_tags($description), 0, 300);
$name = Input::get('Name');
$email = Input::get('Email');
$file = Input::file('Pic');
$package = Input::get('Package');
$countryid = Input::get('Country');
$campuses = Branch::whereHas('Institution', function ($query) use($countryid) {
$query->where('country_id', '=', $countryid);
})->select('id')->get();
//check whether the user with this email existed before
$user = User::where('email', '=', $email);
$firstname = NULL;
$lastname = NULL;
//extract the firstname and last name from the name
if (preg_match('/\\s/', $name)) {
$names = explode(" ", $name);
$firstname = $names[0];
$lastname = $names[1];
} else {
$firstname = $name;
}
if ($user->count()) {
$user = $user->orderBy('id', 'DESC')->first();
} else {
//store the user details
$user = User::create(array('email' => $email, 'firstname' => $firstname, 'lastname' => $lastname));
}
//get the model name
$model = $type;
$result = $this->postUploadPhoto($type, $file);
$the_squeeb_array = array();
foreach ($campuses as $campus) {
$the_squeeb = Squeeb::create(array('model' => $model, 'views' => 0, 'branch_id' => $campus->id, 'create_day' => date("Y-m-d")));
array_push($the_squeeb_array, $the_squeeb->id);
//create the post details
$squeeb_id = 0;
$squeeb_id = $this->createSqueeb($model, $the_squeeb->id, $user->id, $title, $description, $squeeb);
//finally post the squeebe photo
if ($squeeb_id) {
if ($result != FALSE) {
//photos validation
$modelname = $type;
$tablename = lcfirst($modelname) . 's';
$modelphoto = $modelname . 'Photo';
$savesuccess = $modelphoto::create(array($tablename . '_id' => $squeeb_id, 'name' => $result));
}
}
}
if ($user && $the_squeeb) {
if ($squeeb_id) {
$squeeb = Squeeb::where('id', '=', $the_squeeb->id)->first();
View::share('squeeb', $squeeb);
view::share('model', $type);
$the_squeeb_array = implode(",", $the_squeeb_array);
View::share('the_squeeb_array', $the_squeeb_array);
return View::make('guest.advanced_squeeb_preview');
}
}
}
return Redirect::route('advanced_squeeb-get')->with('global', 'Some Error Occured, Please try again');
}