Birdy
1421
8
Eloquent

Eloquent Insert from Select

Posted 3 years ago by Birdy

Hi all,

I’m creating a small application for a specific industry where there are two kinds of end users, a provider in basic terms (A seller) and a user in basic terms (A Buyer).

The user visits the site and requests a free instant quotation/estimation for the service they require, my whole goal for the project is to enable automation for the providers, this is so a provider can send estimations based on the budget the user selects during the form process.

So if a user selects a budget of let’s say £200, The provider will have a default estimation set for that price range within their account management dashboard.

To make it fair we only show 5 estimations to the user per quotation request and we do this by using the random function shipped within laravel and then use the orderBy function to refactor the view in desc order.

The only problem I have is that I’m not advanced with laravel as of yet I’m un sure as to how I can insert the visible 5 estimations provided to a database named saved_estimations so when the user comes back to their account and clicks to view the quotation again the model and controller does not reorder the list in any way from the orderBy or random functions.

So in other words I either only want this to happen once per project id and save the selected 5 providers id's and their estimated prices to a table or if there is another simple way round it as in my view I use a foreach loop to loop through the collect of 5 random selected providers ordering their estimated prices in a descending order.

-- Small update -- Would it be simple enough to just insert the results from the first query where i select the random 5 providers and their estimated prices directly straight into the saved_estimations table, If so what would be the best and most secure way of doing that?


Any input or advice would be greatly appreciated on this.

Thanks

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.