laravel-4

How to add combined unique fields validator rule in Laravel 4

允我心安 提交于 2019-12-18 13:35:32
问题 I am using Laravel 4.2 and mysql db . I have an exam table in which i am taking Exams entry and the fields are --> id | examdate | batch | chapter | totalmarks I have made a combined unique key using $table->unique( array('examdate','batch','chapter') ); in schema builder. Now I want to add a validation rule to it. I know i can add unique validation by laravel unique validator rule but the problem is ,it checks only for one field . I want it to add uniqueness to the 3 fields combined(user

Laravel 4 Auth::attempt using either email or username and password

…衆ロ難τιáo~ 提交于 2019-12-18 13:20:24
问题 In laravel for login attempt I generally use something like this: if (Auth::attempt(array('email' => $usernameinput, 'password' => $password), true)) { // The user is being remembered... } Basically $usernameinput will check with email from my table. I was thinking to do it in a different way, like there is email , username and password in my table. $usernameinput can be either email or username field in my table. How can I Auth::attempt with a condition like: (email==$usernameinput OR

Laravel visitors counter

 ̄綄美尐妖づ 提交于 2019-12-18 13:16:10
问题 I'm trying to build a visitors counter in Laravel.... I don't know what the best place is to put the code inside so that it loads on EVERY page... But I putted it inside of the routes.php.... I think I'll better place it inside of basecontroller? But okay, My code looks like this now: //stats $date = new \DateTime; $check_if_exists = DB::table('visitor')->where('ip', $_SERVER['REMOTE_ADDR'])->first(); $get_visit_day = DB::table('visitor')->select('visit_date')->where('ip', $_SERVER['REMOTE

My composer won't update completely with Laravel 4 it gets stuck with artisan

╄→гoц情女王★ 提交于 2019-12-18 12:56:11
问题 Here is the error I am getting: Script php artisan optimize handling the post-update-cmd event returned with an error [RuntimeException] Error Output: update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-plugins] [--no-custom-installers] [--no-scripts] [--no-progress] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [packages1] ... [packagesN] This shows after: Writing lock file Generating autoload files I tried to delete all my folders

Laravel 4 how to listen to a model event?

戏子无情 提交于 2019-12-18 12:16:22
问题 I want to have an event listener binding with a model event updating . For instance, after a post is updated, there's an alert notifying the updated post title, how to write an event listener to have the notifying (with the post title value passing to the listener? 回答1: The documentation briefly mentions Model Events. They've all got a helper function on the model so you don't need to know how they're constructed. Eloquent models fire several events, allowing you to hook into various points

How to reload/refresh model from database in Laravel?

蹲街弑〆低调 提交于 2019-12-18 12:14:07
问题 In some of my tests, I have a user model I have created and I run some methods that need to save certain attributes. In rails, I would typically call something like user.reload which would repopulate the attributes from the database. Is there a way in laravel to do that? I read through the api and couldn't find a method for it: http://laravel.com/api/4.1/Illuminate/Database/Eloquent/Model.html Any ideas on the "right" way to do this? 回答1: I can't see it either. Looks like you'll have to:

Has one through Laravel Eloquent

旧巷老猫 提交于 2019-12-18 12:13:36
问题 I have three tables garages , cars , securities . The securities are the ones that is keeping one car safe, you can have more than one security, but a single security can keep only one car safe. The garage is where the car is and the securities are as well. What I want is to list all the securities and know the name of the garage that he is. The problem is that securities doesn't have a column containing the id of the garage, only the id of the car that he is keeping safe, but car has the id

Laravel 4 migrate base table not found

邮差的信 提交于 2019-12-18 11:44:59
问题 I'm trying to make following tutorial: https://medium.com/on-coding/e8d93c9ce0e2 When it comes to run: php artisan migrate I get following error: [Exception] SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel.user' doesn't exist (SQL: alter table `user` add `id` int unsigned not null auto_increment prim ary key, add `username` varchar(255) null, add `password` varchar(255) null, add `email` varchar(255) null, add `created_at` datetime null, add `updated_at` datet ime null)

Laravel 4: What to pass as parameters to the Url class?

可紊 提交于 2019-12-18 11:29:39
问题 Can somebody explain the syntax of the Laravel 4 UrlGenerator class? I can't find it in the documentation. I have the following route: Route::resource('users', 'UsersController'); It took me long time to figure out that this: {{ Url::action('UsersController@show', ['users' => '123']) }} generates the desired html: http://localhost/l4/public/users/123 I looked in UrlGenerator.php /** * Get the URL to a controller action. * * @param string $action * @param mixed $parameters * @param bool

Laravel 4 - Package or “modules”?

萝らか妹 提交于 2019-12-18 11:13:21
问题 I'm starting to work with Laravel 4, it seems to be a great choice, anyway before coding my first project i'd like to understand if my usual approach could be ok with laravel. Usually i keep triad for backend and frontend separated under a /modules folder, like this: /modules /backend /config /controllers /models /migrations /ecc.. /frontend (and so on...) With laravel i'm not really sure how to manage this. I'm trying with packages, but the php artisan workbench me/mypackage --resources don