Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Adds make:view Artisan command #48330

Merged
merged 6 commits into from Sep 7, 2023
Merged

[10.x] Adds make:view Artisan command #48330

merged 6 commits into from Sep 7, 2023

Conversation

nunomaduro
Copy link
Member

@nunomaduro nunomaduro commented Sep 7, 2023

This pull request adds the long-awaited make:view Artisan command. As expected, to get started, you simply have to type:

php artisan make:view users.index

INFO: View [resources/views/users/index.blade.php] created successfully.

Here are the contents of the resources/views/users/index.blade.php file. It's a very simple div with an inspirational quote inside:

<div>
    <!-- The best way to take care of the future is to take care of the present moment. - Thich Nhat Hanh -->
</div>

Regarding testing, we've created a custom "testing" stub for this make command. So, if users provide the --test option, they will see the following:

php artisan make:view users.index --test

INFO: View and test [resources/views/users/index.blade.php] created successfully.

And the test's contents:

<?php

namespace Tests\Feature\View\Users;

use Tests\TestCase;

class IndexTest extends TestCase
{
    /**
     * A basic view test example.
     */
    public function test_it_can_render(): void
    {
        $contents = $this->view('users.index', [
            //
        ]);

        $contents->assertSee('');
    }
}

When using the --pest option, they will see the following contents in the test:

<?php

it('can render', function () {
    $contents = $this->view('users.index', [
        //
    ]);

    $contents->assertSee('');
});

Finally, if users wish to have an extension other than blade.php, they can provide the --extension option:

php artisan make:view users.index --extension=php

INFO: View [resources/views/users/index.php] created successfully.

@svenluijten
Copy link
Contributor

As author of sven/artisan-view, I wholeheartedly approve! 👍 While this doesn't have the ability to scaffold the contents of the view the same way my package does, I think it's fine to leave that up to the developer to do manually. Especially with things like Folio, Livewire, custom Blade components, etc. in the ecosystem now, it'd be difficult to find a balance for things to include and the options you'd have to add to this command would get out of hand pretty quickly.

And, FWIW, this would also close the highest voted issue on laravel/ideas! 🎉

@nunomaduro nunomaduro marked this pull request as ready for review September 7, 2023 13:57
Copy link

@josedaian josedaian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nunomaduro,

This is a very good feature!
I only have a doubt about the functions declarations. Is there some reason about don't add the return type into the function declaration?
I mean, not as a docblock.
For example:

protected function getNameInput(): string
{
}

It's just to know 😅.

Your work is incredible!

@taylorotwell taylorotwell merged commit 3caca4c into 10.x Sep 7, 2023
20 checks passed
@taylorotwell taylorotwell deleted the feat/make-view branch September 7, 2023 16:32
coppolafab pushed a commit to coppolafab/laravel-framework that referenced this pull request Sep 8, 2023
* Adds `make:view` Artisan command

* Style

* Sorts method names

* Renames

* formatting

* formatting

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants