https://laravel.io/forum/feedThe RSS feed for the Laravel.io forum contains a list of all threads posted by community members.2024-03-19T03:19:18+00:00https://laravel.io/26905
session()->flash('success', 'Hello world');
return view('dashboard.index');
}
```
However, when using a Breeze generated controller, the session data is not persisted/visible. For example, in the `AuthenticatedSessionController`:
```php
public function store(LoginRequest $request): RedirectResponse
{
$request->authenticate();
$request->session()->regenerate();
return redirect()->intended(RouteServiceProvider::HOME)->with('success', 'You have successfully logged in!');
}
```
^ Note, the above method is simply syntactically "nice". It also fails on `$request->session()->flash('success', 'Hello world');`
If you `{{ var_dump(Session::all()) }}` on a page, this shows as empty for a Breeze controller, and not empty when using a user generated controller.
## Intended behaviour
`var_dump()` should include the `flash()` session data
## Notes
* I've heard that `dd()` quits too early/destroys session data, so `var_dump()` is specified; also:
* This was discovered in finished code - no "manual early exit" issues are the problem
### Steps To Reproduce
## Steps to recreate
* install Laravel
* composer require laravel/breeze --dev
* php artisan breeze:install
* Add a user to the database (using seeder or other method)
* Add a flash message to `AuthenticatedSessionController`, for example: `->with('success', 'You have successfully logged in!')`
* Add `{{ var_dump(Session::all()) }}` to `guest.blade.php` and `app.blade.php`
* Attempt to login
* Monitor the contents of the var_dump(): session data will be empty]]>
2024-03-19T03:19:18+00:00https://laravel.io/27101
Refused to send form data to 'https://mydomain.com/login' because it violates the following Content Security Policy directive: "form-action 'self' https: *.mydomain.com".
I've added a custom directive in my custom CSP with the exact same link with the login request link but it doesn't work. I've read on some forums that it can be caused by Google Chrome blocking any redirected link because it can be dangerous and yeah I use Laravel Redirect intended to redirect the user to the Homeprovider after they log in, but why it only affected the login and logout request? it doesn't affect another form request except those 2. I wonder if there's any solution to this problem, I've searched for many solutions on the internet but none of them seem to be working. Thank you I really appreciate your answer.
This is my login method from LoginController :
```
public function store(Request $request): RedirectResponse {
$this->ensureIsNotRateLimited();
$request->validate([
'email' => ['required', 'string', 'lowercase', 'email', 'max:255'],
'password' => ['required', 'string'],
]);
if(! Auth::guard('admin')->attempt($request->only('email', 'password'), $request->boolean('remember'))) {
RateLimiter::hit($this->throttleKey());
throw ValidationException::withMessages([
'email' => trans('auth.failed'),
]);
}
$notification = array(
'message' => 'Anda berhasil login!',
'alert-type' => 'success',
);
$request->session()->regenerate();
RateLimiter::clear($this->throttleKey());
return redirect()->intended(RouteServiceProvider::ADMIN_DASHBOARD)->with($notification);
}
```
and this is my logout method from LoginController :
```
public function destroy(Request $request): RedirectResponse {
Auth::guard('admin')->logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
return redirect('/admin/login');
}
```
I've added a custom directive in my custom CSP but it doesn't work
```
->addDirective(Directive::FORM_ACTION, 'https://mydomain.com/login')
->addDirective(Directive::FORM_ACTION, 'https://mydomain.com/logout');
```]]>
2024-03-19T03:19:18+00:00https://laravel.io/27099
toArray()
```
Actual result:
```
[
"id" => 1,
"name" => "",
]
```
Excepted result:
```
[
"id" => 1,
"name" => "FOO",
]
```
### Steps To Reproduce
1. Create a User like mentioned in the description
2. Run `User::find(1)->toArray()` in tinker]]>
2024-03-19T03:19:18+00:00https://laravel.io/27100
user_id),
];
}
public function broadcastAs()
{
return 'postCreted';
}
public function broadcastWith()
{
return ['message' => $this->text];
}
}
```
If anyone has encountered this problem and solved it please share]]>
2024-03-19T03:19:18+00:00https://laravel.io/26984
{{ __('Profile') }
{{ __('My Cart') }}
`
The route 'cart' is properly defined on web.php
`
Route::get('/cart', [ViewController::class, 'cart'])->name('cart');
`
The 'cart' method on ViewController returns properly the view, for sure.
It's on the Breeze context that I've been made some changes in terms of views, but don't believe it's related with the Exception itself. Calls the href attribute of the slot on the component, but faithless to be related, since on the slot above (which redirects for the _profile.edit_ route) has no one issue with the same process, besides the point is the route.
>Symfony\Component\Routing\Exception\ RouteNotFoundException
Any insights will be appreciated.]]>
2024-03-19T03:19:18+00:00https://laravel.io/27093
check()) {
return redirect()->route('account.profile');
}
}
return $next($request); // This triggers the error
}
}
```
Hey, I have this middleware that only gives me problems during my live server. I get the following error whenever this middleware is triggered:
Symfony\Component\HttpFoundation\Response::setContent(): Argument #1 ($content) must be of type ?string, Illuminate\Routing\Redirector given
The error points towards return $next($request);
Can someone help me fix this issue? THank You in advance]]>
2024-03-19T03:19:18+00:00https://laravel.io/270982024-03-19T03:19:18+00:00https://laravel.io/27097
belongsTo(Account::class);
}
#my transaction model
BelongsTo::make('Account')
->sortable()
->searchable()
->rules('required')
->required()
->showOnPreview()
->withSubtitles(function ($value) {
return $value->email;
}),
#this is my transaction resource
i have this code but when i try to get email in Subtitles it is showing "No additional information..."
And if i follow officals docs it say use
public function subtitle()
{
return "Author: {$this->user->name}";
}
If i use this then subtitle is not coming
How to use subtitle and how to get email in subtitle?]]>
2024-03-19T03:19:18+00:00https://laravel.io/26954
than 1 seconds (startsecs)
|
| INFO Server running…
|
| Local: http://0.0.0.0:8000
|
| Press Ctrl+C to stop the server
|
| Fatal error: Uncaught Error: Class "Laravel\Octane\Octane" not found in /var/www/html/vendor/laravel/octane/src/Stream.php:57
| Stack trace:
| #0 /var/www/html/vendor/laravel/octane/bin/createSwooleServer.php(19): Laravel\Octane\Stream::shutdown(Object(Swoole\Exception))
| #1 /var/www/html/vendor/laravel/octane/bin/swoole-server(35): require('/var/www/html/v...')
| #2 {main}
| thrown in /var/www/html/vendor/laravel/octane/src/Stream.php on line 57
```
Supervisor Config:
```
[supervisord]
logfile=/var/log/supervisord_octane.log
logfile_maxbytes=40MB
logfile_backups=5
loglevel=info
pidfile=/var/run/supervisord_octane.pid
nodaemon=true
minfds=1024
minprocs=200
user=root
[program:octane]
process_name=%(program_name)s_%(process_num)02d
command=php -d variables_order=EGPCS /var/www/html/artisan octane:start --watch --server=swoole --host=0.0.0.0 --port=8000 --workers=20 --task-workers=auto --max-requests=2000
user=root
autostart=true
autorestart=true
environment=LARAVEL_OCTANE="1"
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
numprocs=1
```
composer dump autoload and artisan cache clear not worked]]>
2024-03-19T03:19:18+00:00https://laravel.io/26827
'$refresh'];
protected function rules()
{
return [
'article.title' => 'required',
'article.content' => 'nullable',
'article.excerpt' => 'nullable',
];
}
public function mount(): void
{
$this->article->load('author', 'media', 'tags');
$this->articleStatus = $this->article->published ? 'published' : 'hidden';
$this->articleHasExcerpt = $this->article->excerpt !== null;
}
public function updatedArticleStatus($value): void
{
if ($value === 'published') {
$this->article->published_at = now();
} else {
$this->article->published_at = null;
}
}
public function editFeaturedImage(): void
{
$this->featuredImageBeingUpdated = $this->article->getFirstMedia('cover');
$this->featuredImageAlt = $this->featuredImageBeingUpdated->getCustomProperty('alt');
$this->editingFeaturedImage = true;
}
public function updateFeaturedImage(): void
{
$this->featuredImageBeingUpdated->setCustomProperty('alt', $this->featuredImageAlt);
$this->featuredImageBeingUpdated->save();
$this->editingFeaturedImage = false;
$this->notify('Featured image updated!');
}
public function removeFeaturedImage(): void
{
$this->article->clearMediaCollection('cover');
}
public function save(): void
{
$this->validate();
$this->article->reading_time = $this->readingTime($this->article->content);
$this->article->content = $this->parseAffiliateLinks($this->article->content);
$this->article->save();
if ($this->featuredImage) {
$this->article->addMedia($this->featuredImage->getRealPath())
->usingName(pathinfo($this->featuredImage->getClientOriginalName(), PATHINFO_FILENAME))
->usingFileName($this->featuredImage->getClientOriginalName())
->toMediaCollection('cover');
}
$this->featuredImage = null;
$this->dispatch('refresh')->self();
$this->notify('Article saved!');
}
public function removeBlogPost(): void
{
$this->article->delete();
$this->redirect(route('admin.articles.list'));
}
/**
* @throws FileDoesNotExist
* @throws FileIsTooBig
*/
public function updatedMediaFile(): void
{
$mimeType = $this->mediaFile->getMimeType();
if (str_contains($mimeType, 'image')) {
$this->validate([
'mediaFile' => 'required|image|max:' . $this->maxUploadSize,
]);
} elseif (str_contains($mimeType, 'video')) {
$this->validate([
'mediaFile' => 'required|mimetypes:video/mp4,video/quicktime|max:' . $this->maxUploadSize,
]);
} else {
$this->reset('mediaFile');
$this->addError('mediaFile', 'Invalid file type. Please upload an image or video file.');
return;
}
$this->uploadMedia();
}
/**
* @throws FileDoesNotExist
* @throws FileIsTooBig
*/
public function uploadMedia(): void
{
$this->article
->addMedia($this->mediaFile->getRealPath())
->usingName(pathinfo($this->mediaFile->getClientOriginalName(), PATHINFO_FILENAME))
->usingFileName($this->mediaFile->getClientOriginalName())
->toMediaCollection('media');
$this->article->load('media');
$this->reset('mediaFile');
}
public function insertMedia(Media $media): void
{
$this->dispatch('tiptap-insert-media', [
'type' => $media->mime_type,
'url' => '/storage/' . $media->getPathRelativeToRoot(),
'alt' => $media->name,
]);
$this->showMediaModal = false;
}
public function deleteMedia(Media $media): void
{
$media->delete();
$this->article->load('media');
}
public function readingTime($content): string
{
$wordCount = str_word_count(strip_tags($content));
$readingTimeInMinutes = ceil($wordCount / 200);
return $readingTimeInMinutes . ' min read';
}
protected function parseAffiliateLinks($content)
{
return preg_replace_callback(
'/@affiliate\s*\[\s*(\d+)\s*,\s*\'(.*?)\'\s*\]/',
function ($matches) {
$affiliate = Affiliate::find($matches[1]);
if ($affiliate) {
return ''.$matches[2].'';
}
// If affiliate not found, return the original text
return $matches[0];
},
$content
);
}
public function getMediaProperty()
{
return $this->article->media;
}
public function render()
{
return view('livewire.admin.article.article-detail')->layout('layouts.admin');
}
}
```
what could be the reason for this issue]]>
2024-03-19T03:19:18+00:00https://laravel.io/26948
validate(['email' => 'required|email']);
$email = $request->input('email');
$status = Password::sendResetLink(['email' => $email]);
return $status === Password::RESET_LINK_SENT
? back()->with(['status' => __($status)])
: back()->withErrors(['email' => __($status)]);
}
```
This is the body of my post request:
```
{
"email": "ilovato@example.com"
}
```
My Pathetic Attempt at Debugging:
- I have confirmed that the 'email' is present in the request body and extracted correctly.
- I've verified my Laravel version, ensuring that it is up-to-date and [follows the current documentation](https://laravel.com/docs/10.x/passwords#password-reset-link-handling-the-form-submission).
- I've made the 'email' field nullable in the password_resets table. However, it registers as an null value.]]>
2024-03-19T03:19:18+00:00https://laravel.io/270902024-03-19T03:19:18+00:00https://laravel.io/27095
$password,
'--password' => $password,
]);
or alternatively
$request = $this->artisan('account:mylogin', [
'--email' => $password,
'--password' => $password,
]);
But for instance with
Artisan::output();
in the test source code I only get
"" or 0 as a return value.
What is to be done in order to return something from the command ?
Best Thanks for your answers !
Poc]]>
2024-03-19T03:19:18+00:00https://laravel.io/270942024-03-19T03:19:18+00:00https://laravel.io/27087
data=$data;
}
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
return new Envelope(
subject: 'Sign Up',
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
view: 'emails.SignUpView',
);
}
/**
* Get the attachments for the message.
*
* @return array
*/
public function attachments(): array
{
return [];
}
public function build(){
return $this->from('finderwebsite1@gmail.com','Finder')
->subject($this->data['subject'])->view('emails.SignUpView')->with('data',$this->data);
}
}
```
MailController :
```php
'bienvenue sur Finder !',
'body'=>'tranquille ? bien ? !'
];
try{
Mail::to('hernandez.mathieu19@gmail.com')->send(new SignUp($data));
return response()->json(['Great ! your soul is mine ^w^']);
}catch(exception $e){
return $e;
}
}
}
}
```
web.php :
```php
[
'smtp' => [
'transport' => 'smtp',
'url' => env('MAIL_URL'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'local_domain' => env('MAIL_EHLO_DOMAIN'),
],
...
```
cache/config.php :
```
...
'mail' =>
array (
'default' => 'smtp',
'mailers' =>
array (
'smtp' =>
array (
'transport' => 'smtp',
'url' => NULL,
'host' => 'mailpit',
'port' => '1025',
'encryption' => NULL,
'username' => NULL,
'password' => NULL,
'timeout' => NULL,
),
'ses' =>
array (
'transport' => 'ses',
),
'postmark' =>
array (
'transport' => 'postmark',
),
'mailgun' =>
array (
'transport' => 'mailgun',
),
'sendmail' =>
array (
'transport' => 'sendmail',
'path' => '/usr/sbin/sendmail -bs -i',
),
'log' =>
array (
'transport' => 'log',
'channel' => NULL,
),
'array' =>
array (
'transport' => 'array',
),
'failover' =>
array (
'transport' => 'failover',
'mailers' =>
array (
0 => 'smtp',
1 => 'log',
),
),
'roundrobin' =>
array (
'transport' => 'roundrobin',
'mailers' =>
array (
0 => 'ses',
1 => 'postmark',
),
),
),
'from' =>
array (
'address' => 'hello@example.com',
'name' => 'Laravel',
),
'markdown' =>
array (
'theme' => 'default',
'paths' =>
array (
0 => '/var/www/html/resources/views/vendor/mail',
),
),
),
...
```
I don't know if I should try to modify cache/config.php again.]]>
2024-03-19T03:19:18+00:00https://laravel.io/27091
@push('page-css')
@endpush
@push('page-header')
@endsection
@push('page-js')
@endpush
`
thank you for your help !]]>
2024-03-19T03:19:18+00:00https://laravel.io/270892024-03-19T03:19:18+00:00https://laravel.io/27019
2.x, origin/HEAD, origin/2.x)
Author: Taylor Otwell
Date: Sun Feb 4 16:49:02 2024 +0100
default to true
✗ [High] Deserialization of Untrusted Data
Path: src/OctaneServiceProvider.php, line 206
Info: Unsanitized input from an HTTP parameter flows into unserialize, where it is used to deserialize an object. This may result in an Unsafe Deserialization vulnerability.
✗ [High] Deserialization of Untrusted Data
Path: src/OctaneServiceProvider.php, line 221
Info: Unsanitized input from an HTTP parameter flows into unserialize, where it is used to deserialize an object. This may result in an Unsafe Deserialization vulnerability.
```
second: in monolog, I use my custom driver and handler (inherited from Abstract ProcessingHandler), thanks to which I collect records in the terminate method of my middleware and send them to storage. they are quite simple and I have limited rights, so I can't attach the full code. so the problem is that records is filled only when processing the very first request after the start of the worker, then in all subsequent requests the write method is called, but records always turns out to be empty. commenting out FlushMonologState does not help. Could you help me understand what the problem is?
i found that the second problem can be solved by turning the singleton binding 'log' into scoped:
/vendor/laravel/framework/src/Illuminate/Log/LogServiceProvider.php
https://github.com/laravel/octane/pull/826/files didn't work for me
i can do it myself, but how many places in laravel should i still think about? is this production-ready? could it be the right solution to redefine all singleton bindings as scoped?
third: sometimes I just get an error. it works stably for 2/3 of the time. what could be the reason for such unexpected behavior?
```
production.ERROR: Call to a member function prepare() on null {"exception":"[object] (Error(code: 0): Call to a member function prepare() on null at /vendor/laravel/framework/src/Illuminate/Database/Connection.php:479)
INFO [stacktrace]
INFO #0 /vendor/laravel/framework/src/Illuminate/Database/Connection.php(809): Illuminate\\Database\\Connection->Illuminate\\Database\\{closure}()
INFO #1 /vendor/laravel/framework/src/Illuminate/Database/Connection.php(776): Illuminate\\Database\\Connection->runQueryCallback()
INFO #2 /vendor/laravel/framework/src/Illuminate/Database/Connection.php(470): Illuminate\\Database\\Connection->run()
INFO #3 /vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2945): Illuminate\\Database\\Connection->cursor()
```
Thanks!
Steps To Reproduce
first problem: use a security checker
second problem: periodically occurs on its own
third problem:
create your own custom handler like this
```
'driver' => 'custom',
'via' => LoggerFactory::class,
'handler' => ApplicationLogHandler::class,
```
throw several exceptions when processing a request
in terminated middleware, try to get GetRecords, they will only be available when processing the first request after the start of the worker]]>
2024-03-19T03:19:18+00:00https://laravel.io/269982024-03-19T03:19:18+00:00https://laravel.io/269922024-03-19T03:19:18+00:00