paduraruionutandrei

paduraruionutandrei

Member Since 1 Year Ago

Experience Points 5,270
Experience Level 2

4,730 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 48
Lessons
Completed
Best Reply Awards 0
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.

30 Aug
2 weeks ago

paduraruionutandrei started a new conversation Monthly Chart

Hello, I want to create a yearly reports based on each month so I want to have something like this: Jan - 3 orders Feb - 4 orders I have an order_date column on my table, but I dont have any idea how to start, I just need an idea for the query, because I must have something like this I guess:

    {   
        "Jan" => 3,
        "Feb" => 4
        ....
    }

Someone can help me. I am using chart js and laravel.

29 Aug
3 weeks ago

paduraruionutandrei left a reply on Ajax Call Problems

Controller method: https://imgur.com/a/SijcW5V Response its empty object: https://imgur.com/vzTG6do

paduraruionutandrei left a reply on Ajax Call Problems

https://imgur.com/a/8sMKdIg , this is the response I got back from server side ( 200 OK ), but still undefined my responnse. The ajax call is made with success because my database change, and it adds the correct data, but something is wrong and I cannot access my data object.

paduraruionutandrei left a reply on Ajax Call Problems

That's the problem my response object is undefined when I try to access it in success function and I cannot figure it out why.

paduraruionutandrei started a new conversation Ajax Call Problems

Hello everyone, I have a problem with ajax call.I have a call where I send some data to laravel backend, something simple.

$(document).ready(function () {
                $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': $('input[name="_token"]').val()
                    }
                });

                $('#create-product').click(function (event) {
                    event.preventDefault();

                    $.ajax({
                        type: 'POST',
                        url: '{{ route('orders.attach-product') }}',
                        dataType: 'json',
                        data: $('.attach-product-form').serialize(),

                        success: function (response) {

                            let id = new Date().getTime();

                            let element = "<div> + ' + response.qty + ' + </div>";

                            $('#attach-products').prepend(element);

                            $('.attach-product-modal').modal('hide');
                            $('.attach-product-form').trigger('reset');
                        },
                        error: function (errorMessage) {
                            console.log('Error: ', errorMessage)
                        }
                    });
                });
            });

Everything works well, database get stored, but I cannot access data properties and I cannot create my dom element with data. Can someone help me please.

This is what I get: https://imgur.com/a/Ulq8iWh

06 Jun
3 months ago

paduraruionutandrei started a new conversation Laravel And Ajax

Hello guys, I have a doubt.I am newbie in Laravel and ajax calls.I just made a simple basic crud, but I don't know if what I did, its pretty ok and not a messy thing.Can you review my code, and tell me your opinion and how can I improve this.I have only 4 days of hard working :).

Blades

@extends('layouts.app')

@section('content')
    <div class="container">

        @include('partials.nav')

        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">Folders</div>

                    <div class="card-body">
                        <!-- Button trigger modal -->
                        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
                            Create folder
                        </button>

                        <!-- Modal -->
                        <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                            <div class="modal-dialog" role="document">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h5 class="modal-title" id="exampleModalLabel">Create</h5>
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                            <span aria-hidden="true">&times;</span>
                                        </button>
                                    </div>
                                    <div class="modal-body">
                                        <form id="create-folder-form">
                                            @csrf

                                            <div class="form-group">
                                                <label for="name">Name</label>
                                                <input type="text" class="form-control" name="name" id="name">
                                            </div>

                                            <div class="form-group">
                                                <button type="button" class="btn btn-primary" id="create-folder">Create</button>
                                            </div>

                                        </form>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row justify-content-center mt-3">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">Folders</div>
                    <div class="card-body">
                        @if($folders)
                            <ul class="folders">
                                @foreach($folders as $folder)
                                    <li data-id="{{ $folder->id }}">
                                        {{ $folder->name }}

                                        <button type='button' class='btn btn-danger delete-folder' data-toggle='modal' data-id='{{ $folder->id }}'>Delete</button>
                                        <button type="button" class="btn btn-primary edit-folder" data-toggle="modal" data-target="#editModal" data-id="{{ $folder->id }}">
                                            Edit
                                        </button>
                                    </li>
                                @endforeach
                            </ul>
                        @endif
                    </div>
                </div>
            </div>
        </div>

        <!-- Modal -->
        <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel">Edit</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <form id="update-folder-form">
                            @csrf

                            <div class="form-group">
                                <label for="name">Name</label>
                                <input type="text" class="form-control" name="name" id="name">
                            </div>

                            <div class="form-group">
                                <input type="hidden" id="hidden-folder" value="0">
                            </div>

                            <div class="form-group">
                                <button type="button" class="btn btn-primary" id="update-folder">Update</button>
                            </div>

                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>

    </div>
@endsection

Ajax Calls

<!-- jQuery 3.x CDN -->
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>

<!-- Create ajax call -->
<script>
    $(document).ready(function() {
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('input[name="_token"]').val()
            }
        });

        $('#create-folder').click(function(e) {
            e.preventDefault();

           $.ajax({
               data: $('#create-folder-form').serialize(),
               url: "{{ route('folders.store') }}",
               type: "POST",
               dataType: "json",

               success: function (data) {

                   if(data.errors) {
                       alert('Sorry');
                   } else {
                       $('#create-folder-form').trigger("reset");
                       $('#exampleModal').modal('hide');

                       $('.folders').append('<li data-id=' + data.id + '>' + data.name + " <button type='button' class='btn btn-danger delete-folder' data-toggle='modal' data-id='" + data.id + "'> Delete " +  "</button>" + " <button type='button' class='btn btn-primary edit-folder' data-toggle='modal' data-target='#editModal' data-id='" + data.id + "'> Edit " +  "</button>" + '</li>');
                   }

               },

               error: function (data) {
                    console.log('Error ' + data);
               }
           })
        });
    });
</script>

<!-- Edit ajax call -->
<script>
    $(document).ready(function() {

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('input[name="_token"]').val()
            }
        });

        $('body').on('click', '.edit-folder', function(e) {
            e.preventDefault();

            let id = ($(this).data('id'));

            $.get('folders/' + id + '/edit', function(data) {
               $('#editModal .modal-body #name').val(data.name);
               $('#editModal .modal-body #hidden-folder').val(data.id);
            });
        });

        $('#update-folder').click(function(e) {
            e.preventDefault();

            let id = $('#hidden-folder').val();

            $.ajax({
               type: 'patch',
               url: 'folders/' + id,
               data: $('#update-folder-form').serialize(),
               dataType: "json",

               success: function (data) {
                   if(data.errors) {
                       alert('Sorry');
                   } else {
                       $('#editModal').modal('hide');

                       $('.folders li[data-id=' + data.id + ']').replaceWith('<li data-id=' + data.id + '>' + data.name + " <button type='button' class='btn btn-danger delete-folder' data-toggle='modal' data-id='" + data.id + "'> Delete " +  "</button>" + " <button type='button' class='btn btn-primary edit-folder' data-toggle='modal' data-target='#editModal' data-id='" + data.id + "'> Edit " +  "</button>" + '</li>');
                   }
               }

            });
        });

    });
</script>

<!-- Delete ajax call -->
<script>
    $(document).ready(function() {

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('input[name="_token"]').val()
            }
        });

        $('body').on('click', '.delete-folder', (function(e) {

            e.preventDefault();

            let id = ($(this).data('id'));

            $.ajax({
                type: 'delete',
                url: "folders/" + id,

                success: function(data) {
                    $('.folders li[data-id=' + data.id + ']').remove();
                }

            });

        }));

    });
</script>

Controller

<?php

namespace App\Http\Controllers;

use App\Folder;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Response;

class FolderController extends Controller
{
    public function index()
    {
        $user = User::findOrFail(Auth::id());

        $folders = $user->folders()->get();

        return view('folders.index', compact('folders'));
    }

    public function store(Request $request)
    {
        $attributes = $request->validate([
            'name' => 'required'
        ]);

        $attributes['user_id'] = Auth::id();

        $folder = Folder::create($attributes);

        return Response::json($folder);
    }

    public function edit($id)
    {
        $folder = Folder::findOrFail($id);

        return Response::json($folder);
    }

    public function update($id, Request $request)
    {
        $folder = Folder::findOrFail($id);

        $folder->update($request->all());

        return Response::json($folder);
    }

    public function destroy(Folder $folder)
    {
        $folder->delete();

        return Response::json($folder);
    }

}

Routes

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Auth::routes(['verify' => true]);

Route::get('/home', '[email protected]')->middleware('verified')->name('home');

Route::prefix('folders')->middleware('verified')->group(function() {

    Route::get('/', '[email protected]')->name('folders.index');

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

    Route::get('/{folder?}/edit', '[email protected]')->name('folders.edit');

    Route::patch('/{folder?}', '[email protected]')->name('folders.update');

    Route::delete('/{folder?}', '[email protected]')->name('folders.destroy');

});

PS: I'm obsessed in writing beautiful code. Thank you so much :) !

04 Apr
5 months ago

paduraruionutandrei started a new conversation What Kind Of Relationship?

Hello, I've some trouble here in understanding something.I have a Member Model, Subscription Model and I want to add check-ins for each subscription. RELATIONSHIPS Subscription belongsToMany Member But I want to show a certain member check-ins, how can I make it.I was thinking about hasManyThrough, but I can't figure it out.

I want to have something like this Access member(1) check-ins, and show some date, check-in date, check-out date, subscription name.

Can you guys help me, please?

25 Feb
6 months ago

paduraruionutandrei started a new conversation CronJob

Hello, I have a cron job who must send an email everyday with some products info.Here is the command.

    class ProductAlert extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'product:alert';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Send an email with product stock alert';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //
        $products = DB::table('products')->whereRaw('product_qty  < product_stock_alert')->get();

        Mail::to('[email protected]')->send(new SendMailable($products));
    }
}

KERNEL

    class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
        'App\Console\Commands\ProductAlert',
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('product:alert')->everyMinute();
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

In my local environment it works fine, but when I add it to cpanel, it does not work.

    php /home/ediagnoza/itrack.ediagnoza.ro/artisan schedule:run > /dev/null 2>&1

Thank you so much.

19 Feb
7 months ago

paduraruionutandrei left a reply on Laravel/Ajax

https://imgur.com/oNfXNlt , this is the problem, at second product added doesnt apply anything(second product is the top one)

paduraruionutandrei started a new conversation Laravel/Ajax

Hello everyone, I've a little problem with my Ajax/Laravel select box.Here is a snippet:

<div style="display: none;">
        @if($products)
            @foreach($products as $product)
                {{@$options .= '<option value="'.$product->id.'">'.ucfirst($product->product_name).'</option>'}}
            @endforeach
        @endif
    </div>

<script>
        $(document).ready(function() {

            $('.add-new-product').click(function () {
                var element = $(
                    '            <div class="row inner-row">\n' +
                    '                <div class="col-xs-12 col-md-4 form-group">\n' +
                    '                    <div class="label-mb"><label class="order-label">Nume Produs</label></div>\n' +
                    '                    <select name="product_name[]" id="" class="order-input chosen">\n' +
                    '                           {!! $options !!}\n' +
                    '                    </select>' +
                    '                </div>\n' +
                    '                <div class="col-xs-12 col-md-4 form-group">\n' +
                    '                    <div class="label-mb"><label class="order-label">Serie Produs</label></div>\n' +
                    '                    <input type="text" class="order-input order-input--half" name="product_series[]" />\n' +
                    '                </div>\n' +
                    '                <div class="col-xs-12 col-md-4 form-group">\n' +
                    '                    <div class="label-mb"><label class="order-label">Cantitate</label></div>\n' +
                    '                    <input type="number" class="order-input order-input--half" name="product_qty[]" value="1"/>\n' +
                    '                </div>\n' +
                    '                <div class="col-xs-12 col-md-4 form-group">\n' +
                    '                    <div class="label-mb"><label class="order-label">Pret Alternativ</label></div>\n' +
                    '                    <input type="number" class="order-input order-input--half" name="product_price[]" required />\n' +
                    '                </div>   ' +
                    '             </div>');
                    
                $('.last').before(element);
            });


        });
    </script>

When I click a button, it adds me a new product to the order, the first product has the autocomplete and search functionality on him, but when I click the button it adds me a new product but without any functionality, just a normal select box.

19 Nov
10 months ago

paduraruionutandrei left a reply on Many To Many Relationship

@YAKAGI - It still doesn't work... I dont know what to do. Here is my form.

<div class="col-xs-12 col-md-4 form-group">
                    <div class="label-mb"><label class="order-label">Nume Produs</label></div>
                    @if($products)
                        <select name="product_name[]" class="order-input">
                            @foreach($products as $product)
                                <option value="{{ $product->id }}">{{ $product->product_name }}</option>
                            @endforeach
                        </select>
                    @endif
                </div>
                <div class="col-xs-12 col-md-4 form-group">
                    <div class="label-mb"><label class="order-label">Serie Comanda</label></div>
                    <input type="number" class="order-input order-input--half" name="product_series[]" required />
                </div>
                <div class="col-xs-12 col-md-4 form-group">
                    <div class="label-mb"><label class="order-label">Cantitate</label></div>
                    <input type="number" class="order-input order-input--half" name="product_qty[]" required />
                </div>
                <div class="col-xs-12 col-md-4 form-group">
                    <div class="label-mb"><label class="order-label">Discount</label></div>
                    <input type="number" class="order-input order-input--half" name="product_discount" />
                </div>

And I dont have OrderProduct Model, should I create it ? I get an array of product qty, Im generate the other one by pressing a button.

paduraruionutandrei started a new conversation Many To Many Relationship

Hello everyone! I've one problem here.I made a many to many relationship(order-products), here are my code snippets.


Controller 

 public function insertOrder(Request $request)
    {
        $order = new Order();
        $order->client_name = $request->input('client_name');
        $order->warehouse = $request->input('warehouse');
        $order->shipping = $request->input('shipping');
        $order->express = $request->input('express');
        $order->awb = $request->input('awb');
        $order->order_date = $request->input('order_date');
        $order->notes = $request->input('notes');
        $order->product_series = $request->input('product_series');

        $order->save();

        $product = Product::find($request->input('product_name'));
        
        foreach($product as $p) {
            $order->products()->attach($p->id);
        }
//
//

//        // update stock
//        $toUpdateProduct = Product::find($request->input('product_name'));
//        $this->updateStock($request, $toUpdateProduct);
//
//        return redirect()->back();
    }

Model for Order

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use App\Product;

/**
 * @property array|null|string client_name
 * @property array|null|string warehouse
 * @property array|null|string shipping
 * @property array|null|string express
 * @property array|null|string awb
 * @property array|null|string order_date
 * @property array|null|string notes
 * @property array|null|string product_series
 * @property array|null|string product_qty
 * @property array|null|string product_discount
 * @property float|int total_order_price
 */
class Order extends Model
{
    protected $fillable = [
      'client_name', 'warehouse', 'shipping', 'express', 'awb', 'order_date', 'notes', 'product_series', 'product_qty', 'product_discount'
    ];

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

Model for Product

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use App\Order;

/**
 * @property array|null|string product_name
 * @property array|null|string product_qty
 * @property array|null|string acquisition_price
 * @property array|null|string marketing_price
 */
class Product extends Model
{
    protected $fillable = [
        'product_name', 'product_qty', 'acquisition_price', 'marketing_price'
    ];

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



I made 50% of the relationship , but ... I want to have more than 1 product to my order, so I just made the part when I can have more products, now I want to add a new column to pivot table(product_qty) that stores the right quantity for the right product(ex: 2 quantity for apples), I cant figure out, what to do, Im stuck with this for 3 days..

11 Oct
11 months ago

paduraruionutandrei left a reply on Multiple Database

I want to migrare the tables avem the database is created, and I really need to make a connection for every user, or I just could use "mysql".

paduraruionutandrei left a reply on Multiple Database

I already saw it, thanks for your answer, but I need a single tenant app, this means a new database for each new client... Single Tenant – A single instance of the software and supporting infrastructure serve a single customer. With single tenancy, each customer has his or her own independent database and instance of the software. Essentially, there is no sharing happening with this option.

Multi-Tenant – Multi-tenancy means that a single instance of the software and its supporting infrastructure serves multiple customers. Each customer shares the software application and also shares a single database. Each tenant’s data is isolated and remains invisible to other tenants.

paduraruionutandrei started a new conversation Multiple Database

Hello everyone, I must develop a web app that manage some gyms(fitness, swimming, etc).I want to use Single Tenancy Principle, one database per each new user.So far I just created a new database, but my migrations doesn't charge, just the database is created.Can you give me so advices, please.Im just a beginner in Laravel. This is my function in DatabaseController:

public function createDB($dbName){ DB::statement('CREATE DATABASE app_' . $dbName);

    // Change the default database name with the new database name
    //config(['database.connections.mysql.database' => $dbName]);

    // Change the database env with the new database
    putenv("DB_DATABASE=$dbName");

    // Migrate same DB Schema for created database
    Artisan::call('migrate', array('--database' => 'mysql','--path' => 'database/migrations'));

    return view('create');
}

I don't know what to do, I'm stuck. Have a nice day!