laravel-4

Laravel Controller Subfolder routing

你说的曾经没有我的故事 提交于 2019-12-17 07:05:29
问题 I'm new to Laravel. To try and keep my app organized I would like to put my controllers into subfolders of the controller folder. controllers\ ---- folder1 ---- folder2 I tried to route to a controller, but laravel doesn't find it. Route::get('/product/dashboard', 'folder1.MakeDashboardController@showDashboard'); What am I doing wrong? 回答1: For Laravel 5.3 above: php artisan make:controller test/TestController This will create the test folder if it does not exist, then creates TestController

Laravel Controller Subfolder routing

坚强是说给别人听的谎言 提交于 2019-12-17 07:04:05
问题 I'm new to Laravel. To try and keep my app organized I would like to put my controllers into subfolders of the controller folder. controllers\ ---- folder1 ---- folder2 I tried to route to a controller, but laravel doesn't find it. Route::get('/product/dashboard', 'folder1.MakeDashboardController@showDashboard'); What am I doing wrong? 回答1: For Laravel 5.3 above: php artisan make:controller test/TestController This will create the test folder if it does not exist, then creates TestController

Laravel orderBy on a relationship

醉酒当歌 提交于 2019-12-17 05:46:10
问题 I am looping over all comments posted by the Author of a particular post. foreach($post->user->comments as $comment) { echo "<li>" . $comment->title . " (" . $comment->post->id . ")</li>"; } This gives me I love this post (3) This is a comment (5) This is the second Comment (3) How would I order by the post_id so that the above list is ordered as 3,3,5 回答1: It is possible to extend the relation with query functions: <?php public function comments() { return $this->hasMany('Comment')->orderBy(

How Can I Set the Default Value of a Timestamp Column to the Current Timestamp with Laravel Migrations?

☆樱花仙子☆ 提交于 2019-12-17 05:34:27
问题 I would like to make a timestamp column with a default value of CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP using the Laravel Schema Builder/Migrations. I have gone through the Laravel documentation several times, and I don't see how I can make that the default for a timestamp column. The timestamps() function makes the defaults 0000-00-00 00:00 for both columns that it makes. 回答1: Given it's a raw expression, you should use DB::raw() to set CURRENT_TIMESTAMP as a default value for a column

Laravel preg_match(): No ending delimiter '/' found

断了今生、忘了曾经 提交于 2019-12-17 05:07:20
问题 Im working on Laravel 4.2. Im trying to use Validator to validate a name field with regex, here is my rule below: public static $rules_save = [ 'class_subjects' => 'required|regex:/[0-9]([0-9]|-(?!-))+/' ]; But as soon as I call the rule to be validated an error is thrown, see below: preg_match(): No ending delimiter '/' found 回答1: Since your regex has a pipe in it, you have to use an array: public static $rules_save = [ 'class_subjects' => ['required', 'regex:/[0-9]([0-9]|-(?!-))+/'], ];

Download files in laravel using Response::download

最后都变了- 提交于 2019-12-17 04:45:14
问题 In Laravel application I'm trying to achieve a button inside view that can allow user to download file without navigating to any other view or route Now I have two issues: (1) below function throwing The file "/public/download/info.pdf" does not exist (2) Download button should not navigate user to anywhere and rather just download files on a same view, My current settings, routing a view to '/download' Here is how Im trying to achieve: Button: <a href="/download" class="btn btn-large pull

Laravel Eloquent groupBy() AND also return count of each group

时间秒杀一切 提交于 2019-12-17 04:22:50
问题 I have a table that contains, amongst other columns, a column of browser versions. And I simply want to know from the record-set, how many of each type of browser there are. So, I need to end up with something like this: Total Records: 10; Internet Explorer 8: 2; Chrome 25: 4; Firefox 20: 4. (All adding up to 10) Here's my two pence: $user_info = Usermeta::groupBy('browser')->get(); Of course that just contains the 3 browsers and not the number of each. How can I do this? 回答1: This is working

file_put_contents(meta/services.json): failed to open stream: Permission denied

放肆的年华 提交于 2019-12-17 03:22:13
问题 I am new to Laravel. I was trying to open http://localhost/test/public/ and I got Error in exception handler. I googled around and changed the permission of storage directory using chmod -R 777 app/storage but to no avail. I changed debug=>true in app.php and visited the page and got Error in exception handler: The stream or file "/var/www/html/test/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /var/www/html/test/bootstrap/compiled.php:8423

Migration: Cannot add foreign key constraint in laravel

て烟熏妆下的殇ゞ 提交于 2019-12-17 02:54:09
问题 I'm trying to create foreign keys in Laravel however when I migrate my table using artisan i am thrown the following error: [Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL : alter table `priorities` add constraint priorities_user_id_foreign foreign key (`user_id`) references `users` (`id`)) My migration code is as so: priorities migration file public function up() { // Schema::create('priorities', function($table) { $table-

laravel throwing MethodNotAllowedHttpException

怎甘沉沦 提交于 2019-12-17 02:11:19
问题 I am trying to get something very basic running. I am used to CI and now learning Laravel 4, and their docs are not making it easy! Anyways, I am trying to create a login form and just make sure that data is posted successfully by printing it in the next form. I am getting this exception: Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException and my MemberController.php: public function index() { if (Session::has('userToken')) { /*Retrieve data of user from DB using