Martin1182

Martin1182

Web Developer at Programer

Member Since 10 Months Ago

Zvolen

Experience Points
2,720
Total
Experience

2,280 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
16
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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 1
2,720 XP
Oct
28
2 days ago
Activity icon

Started a new Conversation Add Products Images (NOVA ADMIN)

Hi, how can we best add images to products in the nova admin panel? Thank you

Oct
27
3 days ago
Activity icon

Started a new Conversation Advanced Nova Media Library

I'm trying to use the Advanced Nova Media Library package and I have a problem with registration.

I have created a Car and db model in which, among other things, I also register car_images where, with the help of the Nova Media Library, pictures for each car are to be stored.

When I paste the code below into my nova model I get this error: Call to undefined method App\Models\Car::getMedia()


use Spatie\MediaLibrary\Models\Media;

public function registerMediaConversions(Media $media = null)
{
    $this->addMediaConversion('thumb')
        ->width(130)
        ->height(130);
}

public function registerMediaCollections()
{
    $this->addMediaCollection('main')->singleFile();
    $this->addMediaCollection('my_multi_collection');
}


 /**
	 * Get the gallery fields for the resource.
	 *
	 * @return array
	 */
    protected function galleryFields()
    {
        return [
            /* Files::make('Single file', 'one_file'), */
            Files::make('Multiple files', 'car_images'),
        ];
    }

Can anyone fix me what I'm doing?

Oct
26
4 days ago
Activity icon

Started a new Conversation Multiple Images Laravel Nova

I need to create an image gallery. I have a Car model I need to add a picture gallery to it. I would like to use Laravel Advanced Nova Media Library. How do I use this package? Well thank you. Mammodel Car where I need a gallery of pictures for a specific car. Should I register this packagev model nova or not? well thank you.

Jul
23
3 months ago
Activity icon

Started a new Conversation Generate PDF Invoice

Good day

Can you advise me on the best way to add another $ products variable to the function? I need the invoice blade then run through the foreach table of products. well thank you

class InvoiceController extends Controller
{
    public function downloadPDF($id)
    {
        $order = Order::find($id);
        $pdf = PDF::loadView('invoice', compact('order'));

        return $pdf->download('invoice.pdf');
    }
}

That's not how it works for me


class InvoiceController extends Controller
{
    public function downloadPDF($id)
    {
        $order = Order::find($id);
        $products = $order->products;
        $pdf = PDF::loadView('invoice', compact('order', 'products'));

        return $pdf->download('invoice.pdf');
    }
}
Jul
08
3 months ago
Activity icon

Replied to Cannot Add Foreign Key Constraint

Hi sorry I'm bothering me again, but I don't understand that I can't start the migration .... What am I doing wrong ??

 public function up()
    {
        Schema::create('order_product', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('order_id')->nullable();
            $table->unsignedBigInteger('product_id')->nullable();

            $table->foreign('order_id')->references('id')->on('orders')->onUpdate('cascade')->onDelete('set null');
            $table->foreign('product_id')->references('id')->on('products')->onUpdate('cascade')->onDelete('set null');

            $table->integer('quantity')->unsigned();
            $table->timestamps();
        });

    }
 public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->nullable();
            $table->foreign('user_id')->references('id')->on('users')->onUpdate('cascade')->onDelete('set null');

            $table->string('billing_email')->nullable();
            $table->string('billing_name')->nullable();
            $table->string('billing_address')->nullable();
            $table->string('billing_city')->nullable();
            $table->string('billing_province')->nullable();
            $table->string('billing_postalcode')->nullable();
            $table->string('billing_phone')->nullable();
            $table->string('billing_name_on_card')->nullable();
            $table->integer('billing_discount')->default(0);
            $table->string('billing_discount_code')->nullable();
            $table->integer('billing_subtotal');
            $table->integer('billing_tax');
            $table->integer('billing_total');
            $table->string('payment_gateway')->default('stripe');
            $table->boolean('shipped')->default(false);
            $table->string('error')->nullable();
            $table->timestamps();
        });
    }
Jul
07
3 months ago
Activity icon

Started a new Conversation File(storage/products/dummy/laptop-1.jpg) Is Not Within The Allowed Path(s):

Hi, I'm getting the following error ... Don't know where the error might be?

Facade\Ignition\Exceptions\ViewException file_exists(): open_basedir restriction in effect. File(storage/products/dummy/laptop-1.jpg) is not within the allowed path(s): (/nfsmnt/:/data/:/usr/php74/:/usr/bin/:/apachetmp:/tmp/:/var/tmp/:/dev/urandom:/usr/lib/x86_64-linux-gnu/ImageMagick-6.8.9/bin-Q16/:/usr/local/bin/:/etc/ssl/certs/ca-certificates.crt) (View: /data/8/1/8120c1e3-a8d3-49dd-abe7-d9b8b3a41100/halaj.online/web/resources/views/product.blade.php)

function productImage($path)

{

    return $path && file_exists('storage/'.$path) ? asset('storage/'.$path) : asset('img/not-found.png');

}
Jul
01
3 months ago
Activity icon

Replied to Cannot Add Foreign Key Constraint

Now I have a problem with seeding


   Illuminate\Database\QueryException

  SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value (SQL: insert into `category_product` (`category_id`, `product_id`) values (1, 1))

  at D:\www\MAGZ-Ecommerce\vendor\laravel\framework\src\Illuminate\Database\Connection.php:671
    667|         // If an exception occurs when attempting to run a query, we'll format the error
    668|         // message to include the bindings with SQL, which will make this exception a
    669|         // lot more helpful to the developer instead of just the database's errors.
    670|         catch (Exception $e) {
  > 671|             throw new QueryException(
    672|                 $query, $this->prepareBindings($bindings), $e
    673|             );
    674|         }
    675|

  1   D:\www\MAGZ-Ecommerce\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:129
      Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value")

  2   D:\www\MAGZ-Ecommerce\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:127
      PDOException::("SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value")


public function up()
    {
        Schema::create('categories', function (Blueprint $table) {
            $table->id();
            $table->string('name')->unique();
            $table->string('slug')->unique();
            $table->timestamps();
        });
    }

public function run()
    {
        // Laptops
        for ($i = 1; $i <= 30; $i++) {
            Product::create([
                'name' => 'Laptop ' . $i,
                'slug' => 'laptop-' . $i,
                'details' => [13, 14, 15][array_rand([13, 14, 15])] . ' inch, ' . [1, 2, 3][array_rand([1, 2, 3])] . ' TB SSD, 32GB RAM',
                'price' => rand(149999, 249999),
                'description' => 'Lorem ' . $i . ' ipsum dolor sit amet, consectetur adipisicing elit. Ipsum temporibus iusto ipsa, asperiores voluptas unde aspernatur praesentium in? Aliquam, dolore!',
            ])->categories()->attach(1);
        }

        // Make laptop have a category of "Desktop" as well.
        $product = Product::find(1);
        $product->categories()->attach(2);

        // Desktops
        for ($i = 1; $i <= 9; $i++) {
            Product::create([
                'name' => 'Desktop ' . $i,
                'slug' => 'desktop-' . $i,
                'details' => [24, 25, 27][array_rand([24, 25, 27])] . ' inch, ' . [1, 2, 3][array_rand([1, 2, 3])] . ' TB SSD, 32GB RAM',
                'price' => rand(249999, 449999),
                'description' => 'Lorem ' . $i . ' ipsum dolor sit amet, consectetur adipisicing elit. Ipsum temporibus iusto ipsa, asperiores voluptas unde aspernatur praesentium in? Aliquam, dolore!',
            ])->categories()->attach(2);
        }

        // Phones
        for ($i = 1; $i <= 9; $i++) {
            Product::create([
                'name' => 'Phone ' . $i,
                'slug' => 'phone-' . $i,
                'details' => [16, 32, 64][array_rand([16, 32, 64])] . 'GB, 5.' . [7, 8, 9][array_rand([7, 8, 9])] . ' inch screen, 4GHz Quad Core',
                'price' => rand(79999, 149999),
                'description' => 'Lorem ' . $i . ' ipsum dolor sit amet, consectetur adipisicing elit. Ipsum temporibus iusto ipsa, asperiores voluptas unde aspernatur praesentium in? Aliquam, dolore!',
            ])->categories()->attach(3);
        }

        // Tablets
        for ($i = 1; $i <= 9; $i++) {
            Product::create([
                'name' => 'Tablet ' . $i,
                'slug' => 'tablet-' . $i,
                'details' => [16, 32, 64][array_rand([16, 32, 64])] . 'GB, 5.' . [10, 11, 12][array_rand([10, 11, 12])] . ' inch screen, 4GHz Quad Core',
                'price' => rand(49999, 149999),
                'description' => 'Lorem ' . $i . ' ipsum dolor sit amet, consectetur adipisicing elit. Ipsum temporibus iusto ipsa, asperiores voluptas unde aspernatur praesentium in? Aliquam, dolore!',
            ])->categories()->attach(4);
        }

        // TVs
        for ($i = 1; $i <= 9; $i++) {
            Product::create([
                'name' => 'TV ' . $i,
                'slug' => 'tv-' . $i,
                'details' => [46, 50, 60][array_rand([7, 8, 9])] . ' inch screen, Smart TV, 4K',
                'price' => rand(79999, 149999),
                'description' => 'Lorem ' . $i . ' ipsum dolor sit amet, consectetur adipisicing elit. Ipsum temporibus iusto ipsa, asperiores voluptas unde aspernatur praesentium in? Aliquam, dolore!',
            ])->categories()->attach(5);
        }

        // Cameras
        for ($i = 1; $i <= 9; $i++) {
            Product::create([
                'name' => 'Camera ' . $i,
                'slug' => 'camera-' . $i,
                'details' => 'Full Frame DSLR, with 18-55mm kit lens.',
                'price' => rand(79999, 249999),
                'description' => 'Lorem ' . $i . ' ipsum dolor sit amet, consectetur adipisicing elit. Ipsum temporibus iusto ipsa, asperiores voluptas unde aspernatur praesentium in? Aliquam, dolore!',
            ])->categories()->attach(6);
        }

        // Appliances
        for ($i = 1; $i <= 9; $i++) {
            Product::create([
                'name' => 'Appliance ' . $i,
                'slug' => 'appliance-' . $i,
                'details' => 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Perferendis, dolorum!',
                'price' => rand(79999, 149999),
                'description' => 'Lorem ' . $i . ' ipsum dolor sit amet, consectetur adipisicing elit. Ipsum temporibus iusto ipsa, asperiores voluptas unde aspernatur praesentium in? Aliquam, dolore!',
            ])->categories()->attach(7);
        }

        // Select random entries to be featured
        Product::whereIn('id', [1, 12, 22, 31, 41, 43, 47, 51, 53, 61, 69, 73, 80])->update(['featured' => true]);
    }

Can you help me?

Jun
30
4 months ago
Activity icon

Replied to Cannot Add Foreign Key Constraint

Yes it already works thank you.

Activity icon

Started a new Conversation Cannot Add Foreign Key Constraint

Hi, Can anyone help me fix a migration bug?

public function up()
    {
        Schema::create('category_product', function (Blueprint $table) {
            $table->unsignedBigInteger('id', true);
            $table->integer('product_id')->unsigned()->nullable();
            $table->foreign('product_id')->references('id')
                ->on('products')->onDelete('cascade');
            $table->integer('category_id')->unsigned()->nullable();
            $table->foreign('category_id')->references('id')
                ->on('category')->onDelete('cascade');
            $table->timestamps();
        });
    }

Error

   Illuminate\Database\QueryException

  SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `category_product` add constraint `category_product_product_id_foreign` foreign key (`product_id`) references `products` (`id`) on delete cascade)

  at D:\www\MAGZ-Ecommerce\vendor\laravel\framework\src\Illuminate\Database\Connection.php:671
    667|         // If an exception occurs when attempting to run a query, we'll format the error
    668|         // message to include the bindings with SQL, which will make this exception a
    669|         // lot more helpful to the developer instead of just the database's errors.
    670|         catch (Exception $e) {
  > 671|             throw new QueryException(
    672|                 $query, $this->prepareBindings($bindings), $e
    673|             );
    674|         }
    675|

  1   D:\www\MAGZ-Ecommerce\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:129
      Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint")

  2   D:\www\MAGZ-Ecommerce\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:127
      PDOException::("SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint")

Thank you for all the help!

Jun
27
4 months ago
Activity icon

Started a new Conversation LARAVEL-VOYAGER

Hi everybody... I use voyager as an admin dashboard. The point is that if I try to make an update and I am logged in as an admin with all rights, it will redirect me to the homepage and role_id will be deleted from the database. Changes will be saved .... This will only happen if the admin wants to edit his data. This does not happen when editing other users. Can you help me? Thank you

Voyager/UsersController.php

namespace App\Http\Controllers\Voyager;

use Illuminate\Http\Request;
use TCG\Voyager\Facades\Voyager;
use Illuminate\Database\Eloquent\Model;
use TCG\Voyager\Events\BreadDataUpdated;
use TCG\Voyager\Http\Controllers\VoyagerBaseController;
use TCG\Voyager\Http\Controllers\Traits\BreadRelationshipParser;

class UsersController extends VoyagerBaseController
{
	use BreadRelationshipParser;

	public function update(Request $request, $id)
	{
		$slug = $this->getSlug($request);

		$dataType = Voyager::model('DataType')->where('slug', '=', $slug)->first();

		// Compatibility with Model binding.
		$id = $id instanceof Model ? $id->{$id->getKeyName()} : $id;

		$data = call_user_func([$dataType->model_name, 'findOrFail'], $id);

		// Check permission
		$this->authorize('edit', $data);

		if (!auth()->user()->hasPermission('edit_roles')) {

			unset($request['role_id']);

			return back()->with([
				'message' => '....ERROR....',
				'alert-type' => 'error',
			]);
		}

		// Validate fields with ajax
		$val = $this->validateBread($request->all(), $dataType->editRows, $slug, $id);

		if ($val->fails()) {
			return response()->json(['errors' => $val->messages()]);
		}

		if (!$request->ajax()) {
			$this->insertUpdateData($request, $slug, $dataType->editRows, $data);

			event(new BreadDataUpdated($dataType, $data));

			return redirect()
				->route("voyager.{$dataType->slug}.index")
				->with([
					'message' => __('successfully_updated') . " {$dataType->display_name_singular}",
					'alert-type' => 'success',
				]);
		}
	}
}
Jun
24
4 months ago
Activity icon

Started a new Conversation Fix Ecommerce Listeners\CartUpdatedListener Error

Hi, Could you help me fix the error I'm getting?

CartUpdatedListener.php

    public function handle($event)
    {
        $couponName = session()->get('coupon')['name'];

        if ($couponName) {
            $coupon = Coupon::where('code', $couponName)->first();

            dispatch_now(new UpdateCoupon($coupon));
        }
    }

Execute the job

public function handle()
    {
        if (Cart::currentInstance() === 'default') {
            session()->put('coupon', [
                'name' => $this->coupon->code,
                'discount' => $this->coupon->discount(Cart::subtotal()),
            ]);
        }
    }

ERROR: Trying to access array offset on value of type null

Jun
03
4 months ago
Activity icon

Replied to API TOKEN

thx.

Activity icon

Replied to API TOKEN

Greetings and if it's Oauth? well thank you

public function githubRedirect() {

    $user = Socialite::driver('github')->user();
    $user = User::firstOrCreate([
        'email' => $user->email,
        'github_id' => $user->id,
        'avatar' => $user->avatar,
    ], [
        'name' => $user->name,
        'password' => Hash::make(Str::random(24)),
    ]);
    Auth::login($user, true);
    
    return redirect('/home')->with('flash', 'HELLO! You are logged in');

}
Jun
02
4 months ago
Activity icon

Started a new Conversation API TOKEN

Good day. When registering a user in the register controller, I would like to call the update function in apiTokenController to automatically create an api_token and save this token in the DB. I want to do this so that the user has api_token assigned to him after registration so that he does not have to request it manually. What is the best way? Well thank you.

protected function create(array $data) {

    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => Hash::make($data['password']),
        'api_token' => Str::random(80),
    ]);
}

public function update(Request $ request) {

    $token = Str::random(60);

    $request->user()->forceFill([
        'api_token' => hash('sha256', $token),
    ])->save();

    return ['token' => $token];
}
May
22
5 months ago
Activity icon

Started a new Conversation AXIOS GET REQUEST

Hi, can you advise me? I'm trying to get an api in the VUE component. It still returns an error. The application runs in laravel. well thank you

mounted: function() {

   return axios(
            `https://newsapi.org/v2/top-headlines?sources=bbc- 
              news&apiKey=2a571f1425d44f8ab56de12e0e0e9b1b`,
            {
	    method: 'GET',
                mode: "no-cors",
                headers: {
                    "Access-Control-Allow-Origin": "*",
                    "Content-Type": "application/json"
                },
                withCredentials: true,
                credentials: "same-origin"
            }
        )
        .then(response => {
            this.posts = [];
            response.data.articles.forEach(posts => {
                this.posts.push(this.extractData(posts));
            });
        })
        .catch(response => {
            console.log(response);
        });

},

error:

Access to XMLHttpRequest at 'https://newsapi.org/v2/top-headlines?sources=bbc-news&apiKey=2a571f1425d44f8ab56de12e0e0e9b1b' from origin 'http://localhost' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

May
01
5 months ago
Activity icon

Replied to Pagination Album Images

Hi, it's not working

Activity icon

Started a new Conversation Pagination Album Images

Hello, can anyone advise me how to do pagination in the model? I have an album with pictures and I would like to see, for example, 20 pictures. Thanks for help

namespace App;

use Illuminate\Database\Eloquent\Model;

class Album extends Model {

protected $fillable =
[
    'title', 'text', 'image'
];
public function images()
{
  return $this->hasMany('App\Image')->latest();
}

}