JohnBraun

JohnBraun

PhD candidate (Organic Chemistry) at VU University Amsterdam

Member Since 2 Years Ago

Netherlands

Experience Points
121,390
Total
Experience

3,610 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
886
Lessons
Completed
Best Reply Awards
52
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 25
121,390 XP
Oct
16
6 days ago
Activity icon

Replied to How To Store Polymorphic Related Model Data

You dont have to save the morphable_id and morphable_type fields yourself. These are taken care of automatically upon saving the relation as specified in the documentation. Youll only need to make sure you have a migration for you pivot table containing these columns.

Oct
12
1 week ago
Activity icon

Replied to Contributing To A Package

i see that you change the name to make sure composer gets the dependency from your file system rather than the one of packaging.

That was my reasoning indeed, but it might also be that composer first checks your defined local repositories before checking packagist. I didnt try that yet actually.

Is there anything wrong with simply cloneing the package into a packages folder in the laravel project root does your solution have any advantages over this?

Well, yes and no. I dont think it matters much what the exact location is of where the package lives, but if you include it in a packages directory in your Laravel app, you should make sure to exclude it from git.

If you take my suggested approach, the package is added to the vendor directory like any package you require by composer, therefore giving a better representation. The vendor directory is by default automatically excluded from git by Laravel, because of this convention.

Activity icon

Replied to How To Access To Laravel User Model From My Custom Package ?

One option is to use a polymorphic relationship. I have written a section on the interaction with Laravel's user model on my blog: Creating a Laravel specific package (part 3) (look for the "Models related to App\User" heading)

Activity icon

Replied to Contributing To A Package

I recently wrote an extensive blog on creating Laravel specific packages on my blog at johnbraun.blog

Generally, my approach is as follows:

Step 1: clone the repo into a packages folder (separate from where I store my Laravel projects)

Step 2: in a (new) Laravel project, I add the code mentioned by @sti3bas to my composer.json, where I use the relative path to the package path (where you just cloned it)

"repositories": [
   {
      "type": "path",
      "url": "../../packages/Laravel-activity",
   }
],

Step 3: in the compose.json file of the package I change the vendor name to my own name (this is a change you dont commit! And Ill explain later why we do this) for example spatie/Laravel-activity would become jhnbrn90/Laravel-activity

Step 4: back in the Laravel project I require the package by with composer require jhnbrn90/Laravel-activity. Although the package is not on Packagist, since we added the local path as a repository to the composer.json file it will still find the package. By using your own name, youre sure that youre using the local package.

Now you have included the package locally and whenever you make a change to the package, that will be reflected in your Laravel app directly.

Hope this helps.

Oct
10
1 week ago
Activity icon

Replied to Testing Process In Laravel Application Development

I am a big supporter of TDD, but I'm not a purist when it comes to the hard separation of what a unit test and a feature/integration test should be. For example, many of my unit tests touch the database (which is considered bad practice by many).

I use a feature test as a way to test the cascading events upon a user's action in the system. Let's say a user registers for a calendar event which should eventually do X, Y and Z. This would fall in my category of feature tests. This test would involve a call to $this->post('some-endpoint', $payload) and make assertions about dispatched Events / Jobs / etc; your desired outcome.

In the unit tests I mostly test that a model has all attributes I expect (making sure the database migrations and model factories are in order) and make sure that certain methods on that model are doing what I expect (yes, even when it needs to interact with the database). For example, when you want to "star" a post, I would test a $post->star() method as a_post_can_be_starred test which checks if a certain column ("starred" for example) was changed from "false" to "true". My apologies for this corny example.

I think it comes down to your personal needs and preference. Do whatever helps the development of your applications most. And above all: just get started with testing and see what you feel comfortable with.

Activity icon

Replied to Why Is Asset() Not Secure?

Aha!

I don't have experience with load balancers, but I am glad that you've solved it 👍

Activity icon

Replied to Laravel Echo, Pusher Not Authenticating On Private Channel

Did you already recompile your assets with npm run dev?

Activity icon

Replied to MorthTo With Multiple Columns

Could you please try to explain what you want to achieve more clearly?

Activity icon

Replied to Why Is Asset() Not Secure?

Thats strange, as I cant reproduce your problem. When using asset() on https I also see that the asset() url is prefixed with https. Did you provide the https prefix in the APP_URL parameter (in .env)?

Are you using Lets encrypt?

I see you could also use the secure_asset() function from the Laravel docs: https://laravel.com/docs/master/helpers#method-secure-asset

Activity icon

Replied to Polymorphic Help

Yes, you are free to update the column types to your needs. I would also not opt for a bigIncrements for the id field, unless youre developing an application with many many users. But these are implementation details.

Good luck!

Oct
08
2 weeks ago
Activity icon

Replied to Polymorphic Help

@movepixels In your specific use case, we could also get around this polymorphic many-to-many relationship by defining an addItem(), removeItem() and getItems() method on your Order model which manually interact with a item_order pivot table (see my suggested migration below). If you also need to reference back from your Subscription / Product / Upgrades model you can do so by adding a orders() method that makes use of the morphToMany() method as provided by Laravel (see below).

Order model

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Order extends Model
{
    public function addItem(Model $model)
    {
        DB::table('item_order')->insert([
            'order_id'     => $this->id,
            'item_id'      => $model->id,
            'item_type'    => get_class($model),
        ]);
    }

    public function removeItem(Model $model)
    {
        $order = DB::table('item_order')
            ->where('item_type', get_class($model))
            ->where('item_id', $model->id)
            ->first();
        
        if (! $order) {
            throw new \Exception
                ('Given model was not associated with this order.');
        }

        return DB::table('item_order')->delete($order->id);
    }

    public function getItems()
    {
        $orderItems = collect(
            DB::table('item_order')
                ->where('order_id', $this->id)->get()
            );

        return $orderItems->map(function ($orderItem) {
            return resolve($orderItem->item_type)::findOrFail($orderItem->item_id);
        });
    }
}

And then set up your pivot table as follows:

"item_order" pivot table

public function up()
{
    Schema::create('item_order', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->unsignedBigInteger('order_id');
        $table->morphs('item');
        $table->timestamps();
    });
}

Reference to an Order

// In your Subscription / Product / Upgrade model
class Upgrade extends Model
{
    public function orders()
    {
        return $this->morphToMany('App\Order', 'item', 'item_order');
    }
}
Activity icon

Replied to SoftDelete On Polymorphic Relationships

Are you using the laravel-activitylog package from Spatie?

If so, looking at the Activity model of the package, you see a subject() method which reads a configuration variable called subject_returns_soft_deleted_models to check if it should include any soft deleted subjects:

// Spatie\Activitylog\Models\Activity

    public function subject(): MorphTo
    {
        if (config('activitylog.subject_returns_soft_deleted_models')) {
            return $this->morphTo()->withTrashed();
        }

        return $this->morphTo();
    }

So, if you set this variable to true (it is set to false by default) in your config/activitylog.php file (which you get after publishing the config file, see their readme on github).


    /*
     * If set to true, the subject returns soft deleted models.
     */
    'subject_returns_soft_deleted_models' => true,
Oct
07
2 weeks ago
Activity icon

Replied to Polymorphic Help

hey @movepixels

Idea is I want to have a Model OrderItem with table "order_items" that will hold all the items for an Invoice. Since the items can come from Subscription, Product, Upgrade models.

I would leave out the intermediate OrderItem model, and just set-up a many-to-many polymorphic relationship between an Order and a Subscription, Product and Upgrade model.

To start, create a new migration to set-up a pivot table for 'orderables':

php artisan make:migration create_orderables_table --create=orderables

In the migration, make sure to add the 'order_id' and 'orderable_id' and 'orderable_type' columns, which we can do via the morphs() helper function:

public function up()
{
    Schema::create('orderables', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->unsignedBigInteger('order_id');
        $table->morphs('orderable');
        $table->timestamps();
    });
}

Ideally, we would like to use $order->items and retrieve all related models. Unfortunately, it is not possible (yet) to gather all underlying models in a many-to-many relationship in Laravel.

Therefore, following the documentation, we need to register all relationships we can have with an Order model.

In your Order model:

public function subscriptions()
{
    return $this->morphedByMany('App\Subscription', 'orderable');
}

public function products()
{
    return $this->morphedByMany('App\Product', 'orderable');
}

public function upgrades()
{
    return $this->morphedByMany('App\Upgrade', 'orderable');
} 

And in the Subscription/Product/Upgrade models:

public function orders()
{
    return $this->morphToMany('App\Order', 'orderable');
}

Now, you can fetch all subscriptions with $order->subscriptions, upgrades with $order->upgrades etc.

And you can fetch all associated orders where an item is included using $subscription->orders, etc.

I hope this helps.

Oct
03
2 weeks ago
Activity icon

Replied to SoftDelete On Polymorphic Relationships

You could check if the model uses soft deletes with the following check:

method_exists($model, 'bootSoftDeletes')

If a model uses soft deletes, you load the withTrashed() version and otherwise you don't.

Activity icon

Replied to How Can I Show Laravel Logs To A Page?

You could try to find a package providing a log viewer functionality. Check Packagist: https://packagist.org/?query=laravel%20log

For example, this package https://github.com/rap2hpoutre/laravel-log-viewer might offer what you want.

Sep
23
4 weeks ago
Activity icon

Replied to Trait Method Conflict

Taken from the PHP documentation about Traits:

Conflict Resolution

In this example, Talker uses the traits A and B. Since A and B have conflicting methods, it defines to use the variant of smallTalk from trait B, and the variant of bigTalk from trait A.

The Aliased_Talker makes use of the as operator to be able to use B's bigTalk implementation under an additional alias talk.

<?php
trait A {
    public function smallTalk() {
        echo 'a';
    }
    public function bigTalk() {
        echo 'A';
    }
}

trait B {
    public function smallTalk() {
        echo 'b';
    }
    public function bigTalk() {
        echo 'B';
    }
}

class Talker {
    use A, B {
        B::smallTalk insteadof A;
        A::bigTalk insteadof B;
    }
}

class Aliased_Talker {
    use A, B {
        B::smallTalk insteadof A;
        A::bigTalk insteadof B;
        B::bigTalk as talk;
    }
}
?>
Sep
08
1 month ago
Activity icon

Replied to Route Model Binding Not Working

@chron That is something we never could have guessed from your question and the code you posted. Please try to formulate your questions better in the future. Please respect peoples time.

If you want to get help, you have to post (the relevant!) code.

Activity icon

Replied to Route Model Binding Not Working

So, I understand that you have the following setup, right?


@foreach ($formdata as $data)
  <form action="{{ route('test.store', $data->id) }}" method="POST">
    @csrf
    <button type="submit">Submit with ID {{ $data->id }}</submit>
  </form>
@endforeach

What happens when you alternatively use a hidden input field?

@foreach ($formdata as $data)

  <form action="{{ route('test.store') }}" method="POST">
    @csrf

    <input type="hidden" name="id" value="{{ $data->id }}">

    <button type="submit">Submit</button>
  </form>
@endforeach

Then the route becomes:

Route::post('test','[email protected]')->name('test.store');

And your controller:

public function store()
{
    dd(request('id'));
}
Sep
04
1 month ago
Activity icon

Replied to Laravel 5.8 Email Verification Not Working With Different Browsers

@hafizur If youre using Laravel 5.8 and properly copied the VerificationController code everything should work. Could you double check your code?

Sep
03
1 month ago
Activity icon

Replied to Is There Such Method In Collection?

Right, that is the result of the map function you have provided. So ... what is your question?

Activity icon

Replied to Is There Such Method In Collection?

Could you elaborate on the problem you have a bit more?

For now, I don't see what you are looking for.

Activity icon

Replied to Common Functions In Laravel

Yes, you can add as many helper functions as you like in the app/helpers.php file.

You could also split them amongst multiple files, as long as you include them in the composer.json 'files' array within the autoloader section.

Activity icon

Replied to Common Functions In Laravel

I believe you want to create your own global helper functions which will be accessible throughout your entire application.

To do so, create a helpers.php file in your 'app' directory, and let's add a function you want globally available:

// helpers.php

function myFunction($message)
{
    return 'this is my ' . $message;
}

Now, let's include your helpers file under a files key in the composer.json file, within the autoload section:

// composer.json

    "autoload": {
        "psr-4": {
            "App\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "files": [
            "app/helpers.php"
        ]
    },

Finally, run composer dump-autoload and try it out in!

You can now run myFunction('message') anywhere in your app.

Activity icon

Replied to Laravel 5.8 Email Verification Not Working With Different Browsers

Hey @hafizur,

You are correct. The VerificationController makes use of the auth middleware, which requires users to first be authenticated before verifying their e-mail address.

To circumvent this, an approach you could take is as follows:

Step 1. Comment out the `auth` middleware from the VerificationController

    public function __construct()
    {
        // $this->middleware('auth');
        $this->middleware('signed')->only('verify');
        $this->middleware('throttle:6,1')->only('verify', 'resend');
    }

Step 2. Override the verify() method from the VerifiesEmails trait

In the VerifiesEmails trait, the verify() method checks if the currently logged in user's ID is equal to the ID of the user that is requested to be verified. We don't want to do this, so we'll override the method in the VerificationController:

public function verify(Request $request)
    {
        // if ($request->route('id') != $request->user()->getKey()) {
        //     throw new AuthorizationException;
        // }

        $user = User::find($request->route('id'));

        auth()->login($user);

        if ($request->user()->hasVerifiedEmail()) {
            return redirect($this->redirectPath());
        }

        if ($request->user()->markEmailAsVerified()) {
            event(new Verified($request->user()));
        }

        return redirect($this->redirectPath())->with('verified', true);
    }

Don't forget to import the necessary classes in the VerificationController:

use Illuminate\Http\Request;
use Illuminate\Auth\Events\Verified;
use Illuminate\Auth\Access\AuthorizationException;

The complete `VerificationController` then looks as follows:

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use Illuminate\Auth\Events\Verified;
use Illuminate\Auth\Access\AuthorizationException;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\VerifiesEmails;

class VerificationController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Email Verification Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling email verification for any
    | user that recently registered with the application. Emails may also
    | be re-sent if the user didn't receive the original email message.
    |
    */

    use VerifiesEmails;

    /**
     * Where to redirect users after verification.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        // $this->middleware('auth');
        $this->middleware('signed')->only('verify');
        $this->middleware('throttle:6,1')->only('verify', 'resend');
    }

    public function verify(Request $request)
    {
        // if ($request->route('id') != $request->user()->getKey()) {
        //     throw new AuthorizationException;
        // }

        $user = \App\User::find($request->route('id'));

        auth()->login($user);

        if ($request->user()->hasVerifiedEmail()) {
            return redirect($this->redirectPath());
        }

        if ($request->user()->markEmailAsVerified()) {
            event(new Verified($request->user()));
        }

        return redirect($this->redirectPath())->with('verified', true);
    }
}
Aug
04
2 months ago
Activity icon

Replied to Session Timeout Redirect To A Lockscreen

If you combine the example as explained in the thread you've posted and this GitHub gist found in this thread, I think you could get your idea working.

Aug
03
2 months ago
Activity icon

Replied to How Do I Set An End Point With An Array Of Values

intial thought

I first thought you wanted to load a bunch of orders using their id, which you would send along to an endpoint like `/api/order/1,2,3,4,5` which would then fetch those orders.

current understanding of your question

However, now I understand from your post that you want to be able to submit those id's as an array.

Instead of using axios.get, I would advise to use axios.post and register the route as Route::post.

In your axios.post call, you specify the endpoint as the first argument and the payload as the second argument. This payload can be your desired array.

axios.post('/api/list/order', ['ids' => [1,2,3,4,5]])
    .then()
    .catch();

Then, in your controller you'll have access to that array of id's:

public function listOrders()
{
    $ids = request('ids'); // [1,2,3,4,5]
    $orders = DB::table('products')->whereIn('id', $ids)->get();
    // etc.
}
Activity icon

Replied to How Do I Set An End Point With An Array Of Values

In the backend you're returning a collection of 'products' from that table where the id's are in the array you 've passed to the endpoint.

What is that you want to achieve on the front end part?

Activity icon

Replied to Laravel Echo Events Render Issue

Did you recompile your assets with npm run dev (or npm run prod / npm run watch)?

Activity icon

Replied to How Do I Set An End Point With An Array Of Values

Well, if you decide to get all orders from a comma separated string in the URL, you can first explode that string into an array:

public function list_order($order = null){

    if ($order == null) {
        abort(404, 'No order was passed');
    }

    $order = explode(',', $order);
    
    $orders = DB::table('products')->whereIn('id', $order)->get();

    return $orders;
}
Jul
30
2 months ago
Activity icon

Replied to Call To A Member Function ToSql() On Array

Cant you produce that query yourself from the combination of values in the query and bindings array?

Activity icon

Replied to AssertSee Videos?

To answer your question we need a little more information regarding your view (blade/vue/...) template

Activity icon

Replied to Call To A Member Function ToSql() On Array

dd(DB::getQueryLog());

Gives you an array, containing the keys 'query', 'bindings' and 'time'.

Activity icon

Replied to Call To A Member Function ToSql() On Array

you also get a 'bindings' key in that array. Doesn't that give you these values?

Activity icon

Replied to Getting Data From Another Website Using Axios

@hjortur17 Ask the owner of the site to add the CORS headers. Alternatively, you might be able to scrape the website.

@martinzeltin that will yield the same error

Activity icon

Replied to Call To A Member Function ToSql() On Array

DB::connection('second_connection')->enableQueryLog();

DB::connection('second_connection')->select("
                 SELECT id, reply_text, sending_time
                 FROM inbox_replies
            ");

dd(DB::getQueryLog());
Activity icon

Replied to Laravel Store Function

You'll have to properly import your User/CommentController

// Admin/CommentsController

use App\Http\Controllers\User\CommentController as UserCommentController;

public function abc()
{
    // ....
    UserCommentController::store();
}

Activity icon

Replied to Start A Project Offline

Have you tried using Homestead yet? That's a great solution for working on Windows

https://laravel.com/docs/5.8/homestead

Activity icon

Replied to Getting Data From Another Website Using Axios

The website does not allow foreign ajax calls.

Activity icon

Replied to Call To A Member Function ToSql() On Array

You already specify the sql query, so what would you try to achieve?

SELECT id, reply_text, sending_time
                 FROM inbox_replies
Activity icon

Replied to Redirect After Login

To bypass the intended path problem, you can define an authenticated method on the LoginController where to redirect to, that takes precedence over the standard intended path.

Wouldn't something like this do the trick?

// LoginController

public function authenticated()
{
    if (auth()->user()->role == 'admin') {
        return redirect('/admin');
    }

    return redirect('/');
}
Jul
29
2 months ago
Activity icon

Replied to Modifying A HasMany() To Return A Row For Each Date In A Relation

@miguelstevens That's completely possible!

Laravel ships with the DateTime library called Carbon. This library has a CarbonPeriod class, which does exactly what you want.

You can use it in the following way:


use Carbon\Carbon;
use Carbon\CarbonPeriod;

$start = Carbon::parse('20 july 2019');
$end = Carbon:parse('25 july 2019');

$period = CarbonPeriod::between($start, $end);

$dates = collect($period)->map(function ($date) {
    return $date->format('d-m-Y');
});

/** $dates is now equal to: 
 [
       "20-07-2019",
       "21-07-2019",
       "22-07-2019",
       "23-07-2019",
       "24-07-2019",
       "25-07-2019",
     ]
**/

However, if you're retrieving the start and end dates from an eloquent model, you can define the column names to be cast to dates already in your base model class:

// Model.php

protected $dates = ['start', 'end'];

Then, you don't have to parse the date first, but directly use them:

use Carbon\CarbonPeriod;

$period = CarbonPeriod::between($model->start, $model->end);

$dates = collect($period)->map(function ($date) {
    return $date->format('d-m-Y');
});
Activity icon

Replied to Modifying A HasMany() To Return A Row For Each Date In A Relation

Could you elaborate a bit more on the actual behaviour of the piece of code you're trying to write?

Activity icon

Replied to App.js Not Updating When Using Vue

Did you register your component in resources/js/app.js?

Vue.component('product-sorting', require('./components/ProductSorting.vue').default);

And did you recompile your assets with Laravel mix (webpack)?

Activity icon

Replied to Displaying An Info-collection Page At Every Login...

Add the following method to your app/Http/Controllers/Auth/LoginController.php:

public function authenticated()
{
    return redirect('/fill-in-this-form');
}
Jul
25
2 months ago
Activity icon

Replied to Database Password Receive From API Request

Actually I don't think it is a good idea to store your password somewhere else than in your .env file.

Is there any particular reason why you want to do this?

Activity icon

Replied to Git Pull Request From Local Branch

Ah, I see.

This is the info from BitBucket themselves:

Pull requests can be used in conjunction with the Feature Branch Workflow, the Gitflow Workflow, or the Forking Workflow. But a pull request requires either two distinct branches or two distinct repositories, so they will not work with the Centralized Workflow. Using pull requests with each of these workflows is slightly different, but the general process is as follows:

  • A developer creates the feature in a dedicated branch in their local repo.
  • The developer pushes the branch to a public Bitbucket repository.
  • The developer files a pull request via Bitbucket.
  • The rest of the team reviews the code, discusses it, and alters it.
  • The project maintainer merges the feature into the official repository and closes the pull request.

https://www.atlassian.com/git/tutorials/making-a-pull-request

Activity icon

Replied to Database Password Receive From API Request

You could override the config() value where DB_PASSWORD is stored at runtime, using:

config(['database.connections.mysql.password' => $passwordFromApi]);

However, I don't know which database driver you're using.

Do note that you can't override .env variables at runtime.

Activity icon

Replied to One Component For Edit/Create Pages

The basic idea is to reuse the same form template for creating and editing a resource (a "page" in your case).

Let's say we have a "title" and a "body" of a page, the form to create a page and edit the page would feature the very same form, except that it is populated in the latter case and the "create" button instead now says "save changes".

Is there something in general you're struggling with?