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

Invalid request class name define in controller #703

Open
aip-jit opened this issue Nov 7, 2024 · 2 comments
Open

Invalid request class name define in controller #703

aip-jit opened this issue Nov 7, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@aip-jit
Copy link

aip-jit commented Nov 7, 2024

  • Laravel Version:11.30.0
  • PHP Version: 8.2.25
  • Blueprint Version: ^2.10
  • Platform: Linux

Issue: When I created the request file, it was successfully made with the correct name, but in the controller, the request class name was different. and also different namespace class import in controller

my generated controller and request file

UserController.php:

<?php

namespace App\Http\Controllers;

use App\Http\Requests\UserControllerStoreRequest;
use App\Http\Requests\UserControllerUpdateRequest;
use App\Models\User;
class UserController extends Controller
{
    public function store(UserControllerStoreRequest $request): RedirectResponse
    {
        $user = User::create($request->validated());

        return redirect()->route('backend.users.show');
    }
    public function update(UserControllerUpdateRequest $request, User $user): RedirectResponse
    {
        $user->update($request->validated());

        $request->session()->flash('user.id', $user->id);

        return redirect()->route('user.index');
    }
}

UserStoreRequest.php

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UserStoreRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'name' => ['required', 'string'],
            'email' => ['required', 'email'],
            'email_verified_at' => ['nullable'],
            'password' => ['required', 'password'],
            'remember_token' => ['nullable', 'string'],
        ];
    }
}

UserUpdateRequest.php

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UserUpdateRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'name' => ['required', 'string'],
            'email' => ['required', 'email'],
            'email_verified_at' => ['nullable'],
            'password' => ['required', 'password'],
            'remember_token' => ['nullable', 'string'],
        ];
    }
}

draft.yaml:

# PLEASE PASTE THE DRAFT FILE WHICH REPRODUCES THE ISSUE HERE...
controllers:
  UserController:
  store:
      validate: user
      save: user
      redirect: backend.users.show
update:
      validate: user
      update: user
      flash: user.id
      redirect: user.index
@aip-jit aip-jit added bug Something isn't working pending This issue is pending review labels Nov 7, 2024
@jasonmccreary
Copy link
Collaborator

Yes, I think I noticed this in a livestream as well. The generated filename (UserStoreRequest) is correct. The type-hint is not.

I welcome a PR from the community to resolve this. Otherwise, I'll try to get to it in the coming weeks.

@jasonmccreary jasonmccreary removed the pending This issue is pending review label Nov 7, 2024
yolcuiskender added a commit to yolcuiskender/blueprint that referenced this issue Nov 10, 2024
@yolcuiskender
Copy link

Hope it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants