laravel-4

Extend/override Eloquent create method - Cannot make static method non static

丶灬走出姿态 提交于 2019-12-05 23:37:20
问题 I'm overriding the create() Eloquent method, but when I try to call it I get Cannot make static method Illuminate\\Database\\Eloquent\\Model::create() non static in class MyModel . I call the create() method like this: $f = new MyModel(); $f->create([ 'post_type_id' => 1, 'to_user_id' => Input::get('toUser'), 'from_user_id' => 10, 'message' => Input::get('message') ]); And in the MyModel class I have this: public function create($data) { if (!Namespace\Auth::isAuthed()) throw new Exception(

Laravel 4 Auth:attempt not working

心不动则不痛 提交于 2019-12-05 23:17:36
问题 I am having hard time working with Laravel 4 Auth::attempt method , followed the right documentation, read couple of SO threads but still i am not able to get it working. $userData = array('email' => 'admin@admin.com','password' => 'admin'); if(Auth::attempt($userData)){ // redirect } else{ echo 'Invalid'; } And it returns Invalid everytime Now i am not sure what is the actual reason. In my config/auth.php i have following <?php return array( /* |----------------------------------------------

Laravel Back to page with old input for validation

不想你离开。 提交于 2019-12-05 23:11:04
For the Update Profile Page I use the route as Route::get('editdriver/{data}', 'DriverController@EditDriver'); And in the controller after validation i use, return Redirect::to('editdriver/'.$data)->withInput()->withErrors($validation->messages()); So, the url will be http://localhost/project/editdriver/1 If i empty the value which is required in the rule and press submit the form, It shows the old data with the validation message. What i need is, It should not show the old value, which is from the db. I even tried., return Redirect::back()->withErrors($validation->messages()); How can i do

Laravel MySQL how to order results in the same order as in whereIn clause

一世执手 提交于 2019-12-05 23:07:24
问题 I have two queries, the first one gives me an array of ids, that is in a specific order. Then that array of ids I pass it to the second query like so: Operation::whereIn('id', $ids)->get(); But when I output the result of that query, the order has changed, if the array $ids was something like (4,2,6,9) which is the order I wanted the results to be in, the output will give me 2,4,6,9. How can I avoid that? 回答1: MySQL way of sorting with order same as in where in clause: $ids; // array of ids

How do inject data into a layout?

陌路散爱 提交于 2019-12-05 23:04:06
I am trying to inject data into a layout (not the sub-view), but I have not found any method that seems practical. These are the two ways I currently know of to accomplish this. The data I will be injecting is the page title, for simplicity. Method 1 // app/controllers/HomeController.php protected $layout = 'main'; public function index() { $this->layout->title = 'Page Title'; $this->layout->content = View::make('home'); } // app/views/layout.blade.php ... <title>{{ $title }}</title> ... Method 2 // app/views/home.blade.php ... @section('title') Page Title @stop ... // app/views/layout.blade

Laravel custom auth filter

做~自己de王妃 提交于 2019-12-05 21:36:36
I've added the standard auth filter to several routes using Route::Intended('/') in the controller (assuming login is successful). filters.php: Route::filter('auth', function(){ if (Auth::guest()) return Redirect::guest('internal/login'); }); Controller: if (Auth::attempt($data, false)) { return Redirect::intended('/'); } How do I go about creating a custom auth filter that checks for a specific permission (isAdmin in this case)? I've made the auth.admin filter the same as the standard auth filter to redirect to the login page, but do I need a second Login method on my controller or is there a

SQLSTATE[HY000] [2005] Unknown MySQL server host 'mysql1.alwaysdata.com:3306' (2)

妖精的绣舞 提交于 2019-12-05 20:21:47
I have this error when i try to access to some web pages of my project: SQLSTATE[HY000] [2005] Unknown MySQL server host 'mysql1.alwaysdata.com:3306' (2) alwaysdata is the phpmyadmin website I use for my database. I noticed that it's when I try to access in some pages in relation with the database (create user for example... etc) and there's no problems with other pages like 'contact'. I'm on mac OSX and I use MAMP server, always data, laravel and netbeans IDE. all configurations required to make the connection between my project and the database is correct. Here it is: SQLSTATE[HY000] [2005]

How to validate a email address domain in Laravel?

做~自己de王妃 提交于 2019-12-05 20:20:25
In Laravel, how do I validate an email address and force it to have a suffix like g.go.edu ? If you want to accept all emails that have suffix g.go.edu , you can use as rule both email and regex rules, for example: $rules['email'] = ['email', 'regex:/(.*)g\.go\.edu$/i']; 来源: https://stackoverflow.com/questions/29720750/how-to-validate-a-email-address-domain-in-laravel

Laravel all routes except '/' return 404

梦想的初衷 提交于 2019-12-05 19:44:56
As the title says, all the routes in my laravel app except the home('/') route result in a 404 error. I have separated the public folder from the rest of the laravel app as represented in the folder structure below. EDIT: I have confirmed that this is not what's causing the problem. This error occurs on both the development system (local) and the production system (shared hosting). EDIT: I forgot to mention: routes work if I go to localhost/index.php/route_name Folder structure: (folder names changed to public/ and laravel/ for convenience) . +-- public/ | +-- index.php | +-- packages/ | +--

Laravel 4: how to write the correct nested controller for nested resource?

十年热恋 提交于 2019-12-05 19:37:56
In Laravel 4, I wish to create a set of restful resources as follows: http://localhost/posts/1/comments http://localhost/posts/1/comments/1 http://localhost/posts/1/comments/1/edit ... So I created two controllers: PostsController and CommentsController (on the same layer), and the routes are written as below: Route::resource('posts', 'PostsController'); Route::resource('posts.comments', 'CommentsController'); I also created a link in /views/comments/index.blade.php referring to routes: posts.comments.create {{ link_to_route('posts.comments.create', 'Add new comment') }} Here's the problem I