laravel-4

Laravel 4 - How to use where conditions for relation's column

泪湿孤枕 提交于 2019-12-21 01:42:18
问题 This is what I want, I have two tables. one is 'Restaurants' and other is 'Facilities'. The tables are simple.. and One-To-One relations. like there is a restaurant table with id , name , slug , etc and another table called facilities with id , restaurant_id , wifi , parking , etc Here are my models: class Restaurant extends Eloquent { protected $table = 'restaurants'; public function facilities() { return $this->hasOne('Facilities'); } } class Facilities extends Eloquent { protected $table =

Laravel MySQL orderBy count

旧城冷巷雨未停 提交于 2019-12-20 23:26:48
问题 I'm using Laravel and MySQL, and I have a table post that represents post where users can comment on it, now I wanna order posts by the number of comments of each post in ascending/descending order, how do I do this in Laravel? I don't want to add a field in post table to keep track of the number of comments of each post, because updating that field manually each time a comment or a comment's comment is added/deleted drives me crazy... This is how I create my posts table and comments table:

How to match input password and database hash password in laravel 4

偶尔善良 提交于 2019-12-20 23:20:55
问题 How to authenticate a user password from a given request in Laravel? How is the password checked against the password hash stored in the database? 回答1: First, you'll need to find the User who is logging in based on email address or username or however you identify them, for example: $user = User::where('email', '=', 'email@address.com')->first(); Then, you'll need to CHECK the hashed password, like so: Hash::check('INPUT PASSWORD', $user->password); This will return true or false based on

Maximum execution time of 30 seconds exceeded Laravel 4 error

匆匆过客 提交于 2019-12-20 20:10:38
问题 I am having an issue with a certain function that sends a password request within my UserController in laravel 4. It checks to see if the email exists in the database then sends an email if the user does. The function then creates a token in a table and sends that at the end of the link within the email. The function works as for as creating the token in the database but it seems to have an issue because i keep getting the Maximum execution time error. I do not know what is causing this, it

Laravel: how to populate a blade SELECT with values from a where statement

回眸只為那壹抹淺笑 提交于 2019-12-20 19:41:14
问题 I understand you can send values to a select statement like this: Controller: $client = Client::lists('name', 'id'); return View::make('index', compact('client')); And populate this in my view like so: View: {{ Form::select('client_id', $client, Input::old('client_id')) }} But how do I populate only records from Clients where group_id = 1 for example. I tried: $client = Client::lists('name', 'id')->where('group_id', 1)->get(); and $client = Client::lists('name', 'id')->where('group_id','=', 1

Prevent Sessions For Routes in Laravel (Custom on-demand session handling)

久未见 提交于 2019-12-20 18:49:11
问题 I am building APIs for my Android app using laravel and default session driver set to REDIS. I found a good article here http://dor.ky/laravel-prevent-sessions-for-routes-via-a-filter/ which sort of serves the purpose. However when ever I hit the url it also hits the redis and generates the key which is empty. Now I want avoid creating empty session keys in redis. Ideally it should not hit the redis How can I do that? Can we customise sessios in a way so that sessions are generated only for

Laravel - Mass Assignment Exception error

五迷三道 提交于 2019-12-20 17:42:09
问题 I am trying to save multiple rows to a table, however, I am presented with a Mass Assignment Error . The error is: Illuminate \ Database \ Eloquent \ MassAssignmentException criteria_id $criteria->save(); $criteria_id = $criteria->id; foreach(Input::get('bedrooms') as $bedroom){ $new_bedroom=array( 'criteria_id' => $criteria->id, 'bedroom' => $bedroom, ); $bedroom = new Bedroom($new_bedroom); $bedroom->save(); } My database structure is: so there isn't any incorrect spelling. The criteria_id

Constructors on classes extending Eloquent

依然范特西╮ 提交于 2019-12-20 17:35:43
问题 I just started a new website and I wanted to make use of Eloquent. In the process of seeding my database, I noticed that I would get empty rows added if I had included any kind of constructor on the model that extends eloquent. For example, running this seeder: <?php class TeamTableSeeder extends Seeder { public function run() { DB::table('tm_team')->delete(); Team::create(array( 'city' => 'Minneapolis', 'state' => 'MN', 'country' => 'USA', 'name' => 'Twins' ) ); Team::create(array( 'city' =>

install multiple Laravel 4 projects to sub directories

心已入冬 提交于 2019-12-20 16:21:32
问题 I'm trying to upload multiple Laravel 4 projects to my web server, not my development server. Each laravel 4 app is housed in their own subdirectory. How should my file structure be? I've searched around for a htaccess to remove the /public from the url but i've been unsuccessful. this server is for testing purposes only, it allows others to follow along as the project is being built. I know their are major security issues with leaving the laravel base structure in these directories, but

Check if request is GET or POST

和自甴很熟 提交于 2019-12-20 16:14:09
问题 In my controller/action: if(!empty($_POST)) { if(Auth::attempt(Input::get('data'))) { return Redirect::intended(); } else { Session::flash('error_message',''); } } Is there a method in Laravel to check if the request is POST or GET ? 回答1: Of course there is a method to find out the type of the request, But instead you should define a route that handles POST requests, thus you don't need a conditional statement. routes.php Route::post('url', YourController@yourPostMethod); inside you