laravel 5 – How to encapsulate an eloquent query in another?

I have a query in Eloquent as follows:

Product :: Join ('sale_prices', 'sale_prices.product_id', 'products', & # 39;)
-> where ("sale_prices.active", 1)
-> get ();

What is translated in:

select * among the products
internal join sale_prices on sale_prices.product_id = products.id
where sale_prices.active = 1;

How can I change the query in eloquent to produce a result like this ?:

select * from (
select * among the products
) p
internal join sale_prices on p.id = sale_prices.product_id
where sale_prices.active = 1

I need to query this way for performance issues (the subquery is actually much more complex than a simple choice * among the products, and the table come_support having millions of millions of dollars. The records slow down the query a lot if I do the inner contents of the subquery.

Thank you so much.

syntax error, unexpected 'if & # 39; (T_IF) in laravel

Do you want to control your username for an administrator and an error if you want, go back to the previous list or the tutorial you want, but you should not go wrong.

meddleware (& # 39; guest: admin & # 39;);
}

public function showLoginForm () {
return the view (& # 39; auth.admin-login & # 39;);
}

public service login (Request $ request) {
// Validate the form
$ this-> validate ($ request, [
            'email' => 'requiered|email',
            'password' => 'requiered|min:6',
        ])

// Attempt to connect the user to
if (Auth :: guard (& # 39;) & # 39;) -> attempt (['email' => $request->email, 'password' => $request->password], $ request-> Remember)) {
// if successful, then redirect to their location
return redirect () -> expected (route (& # 39; admin.dashboard & # 39;));
}

// in case of failure, then redirects to the connection with the form data.
return redirect () -> back () -> withInput ($ request-> only (& # 39; email, & # 39; Remember & # 39;));
}
}

Please indicate that you are online 27, that if, if no error is made.

Problems with the table relationship in laravel

When I type php artisan migrate it generates this error:

        Illuminate  Database  QueryException: SQLSTATE[HY000]: General error: 1005
Can not create `blog`.`products` (errno: 150" foreign key constraint
is malformed ") (SQL: alter table` products`, addition constraint
The `products_user_id_foreign` (` user_id`) foreign key refers to `users`
(`id`) when cascading delete)


Trace of exception:

PDOException: :( "SQLSTATE[HY000]: General Error: 1005 Can not Create a Table
`blog`.`products` (errno: 150" The foreign key constraint is incorrect 

See how my code is

Schema :: create (products, function (Blueprint $ table) {
$ table-> bigIncrements (& # 39; id;);
$ table-> unsignedInteger (& # 39; user_id & # 39;);
$ table-> foreign (& # 39; user_id & # 39;)
-> references (& # 39; id & # 39;)
-> on (& # 39;) & # 39;)
-> onDelete (& # 39; cascade & # 39;);

$ table-> string (& # 39; name);
$ table-> integer (& # 39; amount & # 39;)
$ table-> integer (value & # 39;)
$ table-> timestamps ();
});

Where should I go wrong?

php – How to pass a laravel POST response parameter to Vue.js?

I have a Laravel method that allows me to create an object and save it to the database.

public service store (Request $ request) {
$ this-> validate ($ request,[
        'id_ubicacion' => 'required',
        'id_tipo_inmueble' => 'required',
        'nomenclatura' => 'required',
        'descripcion' => 'max: 100'
    ])

$ createdProperty = Property :: create ($ request-> all ());

return $ createdProperty-> id;
}

As you can see, the method returns data to me.

I call this method using view.js:

createProperty: function () {
var url = & # 39; properties & # 39 ;;
axios.post (url, {
nomenclature: this.nomenclature,
location_id: this.id_location,
id_tipo_family: this.id_tipo_family,
zone: this.area,
description: this.description,
coefficient: this.coefficient,
chip_catastral: this.chip_catastral,
matricula_inmobiliaria: this.matricula_inmobiliaria
}). then (response => {
// I should catch here the value returned by the laravel method
})
}

This done, I must call the value that the laravel method returns to me and be able to use it in the component seen, but I do not know how to proceed.

How to display data in a text field from the combo selection in laravel

Dynamic display of combo selection based on a text field

I would like to display the data in a text field according to the selection of combo boxes in Laravel 5.8. then save the data. Is there a complete tutorial on how to do it from a template, a view and a controller?

In the client controller

public function create ()
{
$ client = client :: all ();
return the view ("Client.create", compact ("Client"));
}

in the create.blade view

 
PEMESAN

I want to increase a value in a field of a database with laravel with updateOrInsert

I have the following code

$ cant = DB :: table (& # 39; s) -> where (& # 39; id_fac_enc, ###, $ request-> input (& # 39; idfactura -> where ('product_id', = $, $ array_ids[$i]) -> select (& # 39;) -> get ();
DB :: table (& # 39; fac_det & # 39;) -> updateOrInsert (['id_fac_enc'=>$request->input('idfactura')'id_producto'=>$array_ids['Id_fac_enc'=>$request->input('idfactura')'id_producto'=>$array_ids['id_fac_enc'=>$request->input('idfactura')'id_producto'=>$array_ids['id_fac_enc'=>$request->input('idfactura')'id_producto'=>$array_ids[$i]],['cantidad' => $cant])

but I get the following error:

enter the description of the image here

Doubt with query type in controllers, Laravel 5.5

Well, the question is whether it is possible to insert a query with normal SQL in a controller, without the need for a query builder or eloquen, if possible, how to insert it?

php – Adds an error to the Laravel 5.5 error pack

First of all, greetings. I need the following lines of code instead of redirecting me to a view and displaying an error message, send me the error to the Laravel error bag for to be able to capture it in the view. I have doubts about this and I would like to know. how to send the error of this method to Laravel 5.5 bag errors.

$ aux = $ request['carro_id']; // save the value stored in the foreign key column
$ model = Model :: where (& # 39; car_id & # 39 ;, aux) -> get (); // find the car models with the car.id file of the new model to add.
if ($ model) {// if different from empty
foreach ($ model as $ m) {
if ($ m-> number == $ request-> number) {// with search for a match between the new number and an existing one, the error is returned
return redirect () -> route (& templates) -> with (& # 39; danger_msg & # 39; WARNING the model is already registered! & # 39;);
}
}
}

PD I've looked in the official documentation, in the validations and I do not see how to adapt what they explain to my method.

Datatables – Completely remove a migration (with your class) in Laravel. Delete table

I have a problem when creating tables again, he tells me that the class already exists.

My problem from the beginning was that I created the messy tables just like the list.

  • Table languages
  • Table experiences
  • User table

When I had to create them in that order.

  • User table
  • Table languages
  • Table experiences

Indeed, the tables below (Languages ​​and Experiments) have a foreign key that depends on the Users table.

Then I decided to create them again, delete them "manually", just delete the files, and when you try to run the command again

Hand-made php: migration create_user_table

I get the error that the class already exists.

InvalidArgumentException: A CreateUsuariosTable class already exists.

protected function verifyMigrationDoesntAlreadyExist ($ name)
{
if (class_exists ($ className = $ this-> getClassName ($ name))) {
throws new InvalidArgumentException ("A class {$ className} already exists.");
}
}

I was looking in the forum and found that it can be used

Schema :: dropIfExists (& # 39;) & # 39;);

Schema :: drop (& # 39; languages);

but it does not work for me or I apply it badly.

I hope you can help me with that, thank you.

laravel – CLI view or use View with webpack?

Hello, I will develop an application from scratch.

I will use it as a development stack.

-php (pure Laravel background).
-view (vuetify, vuerouter, vuei18n, etc.)
-SQL serve

I was wondering what was best for building the spa, whether you use it dry view or without a cli or if you were using view with your cli.

To date, he had used it without his insurance. But I understand that it is better to use the CLI, which is not difficult to integrate with laravel and with websokects.

They have experience in developing applications in this way.

It should be noted that it is a fairly complex application. This will have specialization modules. For what I have to do with asynchronous loads in the spa, I have never done this with the CLI and I do not know how to specify it in the CLI Webpack.

Greetings