Buy your loved one the ultimate gift. Lifetime gift certificates are $100 off.

tomas95go

Experience

8,440

1 Best Reply Awards

  • Member Since 11 Months Ago
  • 75 Lessons Completed
  • 0 Favorites

22nd May, 2017

tomas95go left a reply on Searching, Where And/or Where • 6 months ago

@SCC Never give you a thank you for this! It is working really good :D!

20th May, 2017

tomas95go started a new conversation Is This A Good Way To Solve This Problem? • 6 months ago

Hi everyone, so here is the situation, I want to know if this is a good way to solve the problem that I had, wich is discount quantity of a product and adding the selled quantity to another table (to make a chart later like, "These are the most selled products"). I learned this way of solve problem when I was in my first year of University but I think is not good for Laravel.

I got this in a Request file:

public function persist()

    {

        $codigo_ingresado_por_usuario = request('codigo'); //get the code entered by the user and store it in a var.

        $cantidad_ingresada_por_usuario = request('cantidad'); //get the quantity entered by the user and store it in a var.

        $cantidad_almacenada_en_bd = DB::table('productos')->where('codigo', $codigo_ingresado_por_usuario)->value('cantidad'); //get the quantity of the product with code that the user entered and store it in a var.

        if ($cantidad_ingresada_por_usuario > $cantidad_almacenada_en_bd){
    //if quantity entered by the user > quantity of the product in the bd do:
            return back()->withErrors([

                'message' => 'La cantidad ingresada supera a la cantidad disponible en el Stock'
                    //The entered quantity exceeds the quantity available in stock.
            ]);

            }else{

                DB::table('productos')->where('codigo', $codigo_ingresado_por_usuario)->decrement('cantidad', $cantidad_ingresada_por_usuario);  //decrement the quantity of the product  

                $obtener_descripcion_producto = DB::table('productos')->where('codigo', $codigo_ingresado_por_usuario)->value('descripcion'); //get the description of the product to insert into the table.

                DB::table('transaccions')->insert(['codigo' => $codigo_ingresado_por_usuario,
                    'descripcion' => $obtener_descripcion_producto,
                    'cantidadSaliente' => $cantidad_ingresada_por_usuario,
                    'created_at'=> Carbon::now(),
                    'updated_at'=> Carbon::now()]);
        //insert all the data to the table wich is going to be good to make a chart.
            } 

    }

And then in my controller:

    public function realizarTransaccion(realizarTransaccion $request)
    {
    //realizarTransaccion = makeTransaction
        $request->persist();
     
        return redirect('/realizarTransacciones'); 

    }

Another thing, I want to know if it is possible to show the description of the product in my view Currently I'm displaying just the code and the quantity that the user wants to sell, how can I put a readonly field for showing the description?

And my last doubt, the way I solved my problem is not the best I think, because I can sell only ONE product at time, how can I sell multiple products? I think a good way us a while loop.

NOTE: I'm not using libraries cause it is for my university subject, we are allow to use some basic ones.

4th May, 2017

tomas95go started a new conversation Trying To Understand Gates/Policies/Middleware • 7 months ago

Hi everyone, What I'm trying to achieve is the following:

I got two type of users for my program, Administrator and Employee, they are related for the following relations:

Two models, no pivot table of:

Role:

public function users()

            {

                return $this->hasMany(User::class);

            }

User:

public function role()

        {

            return $this->belongsTo(Role::class);

        } 

Also I got a CRUD for Products and a CRUD for Users, I want to restrict some actions to the "Employee" so he can not do the CUD actions(Just want to hide the buttons to create, update and delete on the view that shows all the Products) and in the view related to the Users, I do not want that the "Employee" has access to it.

Another thing, I already implement a middleware for non authenticated user's, but this one with roles and permissions is not that easy or I just don't understand it.

So, how can I achieve that with Gates or Policies or even Middleware?

I tried to follow the documentation, but, I don't know what I'm doing for being honest, so I deleted all that I did related to this and I'm asking you guys now.

Note: If you need any peace of code of my program, just ask for it :)!.

  1. Is necessary to have 3 tables to accomplish this?
  2. Is necessary to have a relation between User or Role with Products?
  3. If you share with me some code, please give me some perspective, only if you have time :). 4)So, how can I achieve that with Gates or Policies or even Middleware?

Thanks in advance!

27th April, 2017

tomas95go left a reply on How To Make A Delete Confirmation Window With Sweet Alert • 7 months ago

@Screenbeetle Hi!

Yes, that's exactly how I did it (when I remove the Alert reference from the controller), the window is still not popping out, I'm starting thinking may be I installed Sweet-Alert in a wrong way and that's why I can do simple stuff but no use functions like the one in your code.

26th April, 2017

tomas95go left a reply on How To Make A Delete Confirmation Window With Sweet Alert • 7 months ago

@Screenbeetle

Does the delete route work without SA?

Yep it is working perfectly, what I want to avoid is making a redirect to another view just for the confirmation of the delete. I want this alert because I do not want to interrump the "flow" of the program and offer a better user exprience, I'm going to do it if I do not have another alternative though.

By the way, the code that I copy from you yesterday is not generating a button, I do not know if it is my mistake or what, but I add the button like a showed you in my comment also I past that code in the view with the form dunno if the Script goes there.

Are you including the SA library (in blade page/layout) before making the call?

Yes, I'm including the '@include('sweet::alert')' in the view if that what u mean. In the controller I got it this way. And in the masterlayout I got the references:

" " "" ""

public function destroy($id)
    {
        
        $productos = Producto::find($id);

        if($productos != null) {

            $productos->delete();

            Alert::success('Do you want to delete this record','Confirmation');

            return redirect()->action('[email protected]');

        }

        return redirect()->action('[email protected]');

    }

Are you getting any JS errors? Clashing with another script maybe?

I don't think so, I can't tell you that exactly, because I don't know how a JS error is desplayed :(, the window is just popping out, and the record is being deleted anyways, not waiting for the user to confirm it.

@Cronix, @Screenbeetle I'm not getting it quite clear for being new to this stuff, I think you guys refer to the code storage in my "Public/dist/", but wich one is it? I got two files with js: "sweetalert-dev.js" and "sweetalert.min.js",I got a third file but that one is for the css. I have to say I did not touch any of this three files.

@Screenbeetle if u say that I can not relay on Sweet Alert for preventing an user to delete a record accidentally, how can I do it?

Oh and I did not thank you two for answering yesterday, sorry, thanks for helping me :D.

25th April, 2017

tomas95go left a reply on How To Make A Delete Confirmation Window With Sweet Alert • 7 months ago

@Cronix what code are you talking about? The css and js? or the function I tried to do? This last thing, I erase that function cause I didn't make it to work,I tried to apply the function that it's in the link I put on the thread.

@Screenbeetle

I put the peace of code u gave me and adapt it to my routes, but it is still not working.

{{ Form:: open(['method' => 'DELETE','route' => ['administrarStock.destroy', $producto->id], 'id' => 'confirm_delete']) }}

                        {!! Form::submit('Eliminar', ['class' => ' btn-danger']) !!}

                          <script type="text/javascript">
                            $(document).ready(function(){
                                $( "#confirm_delete" ).submit(function( event ) {
                                    event.preventDefault();
                                    swal({
                                        title: 'Are you sure?',
                                        text: "Please click confirm to delete this item",
                                        type: 'warning',
                                        showCancelButton: true,
                                        confirmButtonColor: '#3085d6',
                                        cancelButtonColor: '#d33',
                                        confirmButtonText: 'Yes, delete it!',
                                        cancelButtonText: 'No, cancel!',
                                        confirmButtonClass: 'btn btn-success',
                                        cancelButtonClass: 'btn btn-danger',
                                        buttonsStyling: true
                                    }).then(function() {
                                            $("#confirm_delete").off("submit").submit();
                                    }, function(dismiss) {
                                        // dismiss can be 'cancel', 'overlay',
                                        // 'close', and 'timer'
                                        if (dismiss === 'cancel') {
                                            swal('Cancelled', 'Delete Cancelled :)', 'error');
                                        }
                                    })
                                });
                            });
                        </script>

                        

                        {!! Form::close() !!}

tomas95go started a new conversation How To Make A Delete Confirmation Window With Sweet Alert • 7 months ago

Let me be clear for you people :), I already found the answer to this issue in this link

https://laracasts.com/discuss/channels/laravel/confirm-delete-using-sweetalert

The problem is, I do not know how to implement that answer in my code, I just start using Sweet Alert today and I manage to setup basic messages like "Success! You are now loged in" kind of stuff.

Also I try to get an answer on Google, not having result's cause I don't know JavaScript either.

So, I'm asking for help here because I only need this kind of Window for my project (at least for now).

Laravel version: 5.4.19

S.O: Windows 10.

Enviroment: virtualized Homestead version 2.2.2 on a VirtualBox VM.

Additional packages: Laravel Collective for the forms and Sweet Alerts as I mentioned at the beginning of the thread.

This is my code:

ControladorProductos.php: (ProductsController in english)

‚Äč```php

24th April, 2017

tomas95go left a reply on SQLSTATE[HY000]: General Error: 1364 Field 'reset_token' Doesn't Have A Default Value • 7 months ago

May be it's going to sound stupid, but did you try it the "normal" way?

public function up() { Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('password'); $table->rememberToken(); $table->string('email'); $table->timestamps(); }); }

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::dropIfExists('users');
}

Something like that

23rd March, 2017

tomas95go left a reply on Searching, Where And/or Where • 8 months ago

@SCC Hi! Could you please show your form? I'm having struggle with this, and also show me your Model and Controller for the Search action, thanks in advance.

16th March, 2017

tomas95go left a reply on I Never Know How To Start A Project • 8 months ago

Thanks for answering @Impart @tykus @Cronix , I'm taking it easy now and doing what u say guys, grabed a notepad and using my white board to start the design of the project, doing that kind of cool me off.

tomas95go started a new conversation I Never Know How To Start A Project • 8 months ago

Hi everyone, I think this a problem that I always have whenever I try to start programming a Project.

I never know how to start it, I just finished the series "Laracasts 5.4 from Scratch" and when I wanted to start my personal project, I'm just in shock, I'm a begginer with Project Development.

I want to do a Stock Managment System, where should I start? Anyone has any hints that I can use or recommend books or tutorials to how to start a Project? or may be you guys can share the approach you have when u want to do somethin.

8th March, 2017

tomas95go left a reply on MySQL GUI Does Not Refresh My Tables Using Homestead • 9 months ago

I Really dunno What I did but it's working now.

tomas95go started a new conversation MySQL GUI Does Not Refresh My Tables Using Homestead • 9 months ago

Hi people, I'm stuck in the episode "Laravel 5.4 From Scratch: Working With the Query Builder".

The thing is you have to migrate a new table, the migration is working,but the problem is MySQL GUI is not showing me the correct tables and the correct data.

Things to consider: Im a Windows 10 user, Im using Vagrant and Homestead with a Virtualbox provider.

If go via Homestead SSH/Vagrant SSH and enter to MySQL via:

mysql -u user -p

use libreria; //name of my database.

show tables;

show, obviusly the tables that I currently have:

http://imageshack.com/a/img923/9744/u0d62j.jpg

But in the MySQL GUI (Using SQLyog):

http://imageshack.com/a/img923/4660/s4jdwo.jpg

Note: Also I have a add a field to "tasks" called "body" but it is not reflected on the GUI! and I have two more tables "create_users_table" and "create_password_resets" that the GUI is not showing.

This is the way I'm doing the connection on SQLyog:

http://imageshack.com/a/img921/1810/Y4f0Ra.jpg

http://imageshack.com/a/img921/1609/lmwYcF.jpg

This my .env file:

http://imageshack.com/a/img922/5780/0frOJP.jpg

This is my Homestead.yaml file:

http://imageshack.com/a/img923/9316/D5Ztsq.jpg

Another question the folders map and the sites map are ok?

This is the location of my code:

D:\Proyectos\miLibreria

19th January, 2017

tomas95go left a reply on Problems With The PHP Practitioner Series Episode 16 • 10 months ago

@eldelmonico @jasoking92 sorry for the late reply, when you 're talking about the directory of the code, is in the right carpet (htdocs on XAMPP), i'm not using Laravel, this is pure php.

How can I upload the code so you can take a look at it? cause Router.php uses other codes to execute.

If u still want the code from Router.php, this is the one:

5th January, 2017

tomas95go left a reply on Problems With The PHP Practitioner Series Episode 16 • 11 months ago

@ejdelmonico Thanks for answer, yeah I know that, but that's the weird thing! the route is defined, I follow the instructions of the video step by step like I always do, that's why I don't know what's going on. I checked the solutions that people come up on the comments on the video but nothing it's working.

2nd January, 2017

tomas95go started a new conversation Problems With The PHP Practitioner Series Episode 16 • 11 months ago

Hi Everyone, I'm very happy that I'm learning PHP with such a good teacher like Jeffrey however im having problems with this Episode.

I keep getting the same error message:

Fatal error: Uncaught Exception: No route defined for this URI in D:\Xamp\htdocs\laracast-curso1\core\Router.php:35 Stack trace: #0 D:\Xamp\htdocs\laracast-curso1\index.php(8): Router->direct('laracast-curso1...') #1 {main} thrown in D:\Xamp\htdocs\laracast-curso1\core\Router.php on line 35

I already try the solutions that other user's metion in the comments of the episode, and I still can't fix this.

I'm using Xampp.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.