Tray2

Tray2

Oracle Developer (PL/SQL, Forms & Apex) at Scania CV AB

Member Since 5 Years Ago

Solna

Experience Points
323,350
Total
Experience

0 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
1426
Lessons
Completed
Best Reply Awards
274
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 50
323,350 XP
Sep
27
4 hours ago
Activity icon

Awarded Best Reply on How To Use Old() Helper In Input Fields Of Laravel Blade

You can do something like this to handle dropdowns.

 <select name="genre_id" required>
     @if(old('genre_id'))
         <option value="" disabled>Select your genre</option>
     @else
         <option value="" disabled {{ isset($book) ? '' : 'selected' }}>Select your genre</option>
     @endif
     @foreach($genres as $genre)
        <option value="{{ $genre->id }}" {{ isset($book) && $book->genre_id == $genre->id ? 'selected' : '' }}>{{ $genre->genre }}</option>
     @endforeach
 </select>
Sep
26
1 day ago
Activity icon

Replied to Understanding Eloquent's Magic Functions

It's most likely defined in a policy or a middleware.

Activity icon

Replied to How To Use Old() Helper In Input Fields Of Laravel Blade

You can do something like this to handle dropdowns.

 <select name="genre_id" required>
     @if(old('genre_id'))
         <option value="" disabled>Select your genre</option>
     @else
         <option value="" disabled {{ isset($book) ? '' : 'selected' }}>Select your genre</option>
     @endif
     @foreach($genres as $genre)
        <option value="{{ $genre->id }}" {{ isset($book) && $book->genre_id == $genre->id ? 'selected' : '' }}>{{ $genre->genre }}</option>
     @endforeach
 </select>
Activity icon

Replied to String Data, Right Truncated: 1406 Data Too Long For Column 'image' At Row 1

Like previously mentioned never store an image in the database.

However you should use a clob or a blob to store the base64 image.

Unfortunately Laravel migration doesn't support those types out of the box so you would have to use a db:statement to create that table.

https://stackoverflow.com/questions/51824304/laravel-add-clob-column

But like I said store the image on disc it will keep the database fast and agile.

Activity icon

Replied to Can't Use Where Clause After Union Of 2 Queries

That is what I meant with a one to one relation, There you can use a database view but with a one to many or many to many you can't since you will get "Subquery returns more than one row".

Unless of course if you concatinate the result from that subquery.

Activity icon

Replied to Can't Use Where Clause After Union Of 2 Queries

I put all the relations in the database model inside the database view so I would never need to use any kind of eagar loading on my view.

I'm not sure exactly what you are trying to achieve in your query since I'm more of a SQL developer than query builder person.

Without knowing your database model and the expected result it's hard to grasp what you are trying to achieve.

Eagar loading is just a fancy way of doing this

SELECT t1.*, t2.* 
FROM table1 t1,
           table2 t2
WHERE t1.id = t2.table1_id;

// The same as in a one to one relation//

Table1::with('table2')->get()

I might go with either approach when it's just one or two tables. If it's more complex I always go with a database view since it's so much easier to sort and filter on a single model.

If you have a one to many then you can't use the database view technique, you will need at least two queries.

Activity icon

Replied to Can't Use Where Clause After Union Of 2 Queries

The Eloquent way so to speak isn't always the most eloquent way to do stuff unfortunately. When it comes to more complex queries like the one below (taken from my mediabase project).

SELECT DISTINCT (SELECT GROUP_CONCAT(a.id ORDER BY a.id SEPARATOR ',')
                     FROM authors a, author_books ab
                     WHERE a.id = ab.author_id
                     AND ab.book_id = b.id) author_id,
                    (SELECT GROUP_CONCAT(concat(a.last_name, ', ', a.first_name)
                     ORDER BY a.last_name, a.first_name SEPARATOR ' & ')
                     FROM authors a, author_books ab
                     WHERE ab.author_id = a.id
                     AND ab.book_id = b.id) author_name,
                     b.id book_id,
                     b.title,
                    (SELECT ROUND(AVG(s.score), 1) 
			FROM scores s 
			WHERE s.item_id = b.id AND media_type_id = 1) rating,
                    b.series,
                    b.part,
                    b.released,
                    g.id genre_id,
                    g.genre,
                    f.id format_id,
                    f.format,
                    CASE series
                    	WHEN 'Standalone' THEN b.released
                    	ELSE (SELECT MIN(bi.released) FROM books bi WHERE bi.series = b.series)
                   	END series_started,
                    bc.user_id
                FROM authors a,
                    books b,
                    genres g,
                    formats f,
                    book_collections bc
                WHERE b.genre_id = g.id
                AND   b.format_id = f.id
                AND   b.id = bc.book_id

As you can see it uses five tables and a couple of inline views. To create something like this in the query builder would be way more complex. So what I like to do is create a database view to pull in the data I need from the tables I need. To create one of these database views is very simple. A migration could look lile this.

class CreateBookCollectionViews extends Migration
{
    public function up()
    {
            DB::statement(
                "CREATE OR REPLACE VIEW book_collection_views AS
                SELECT DISTINCT (SELECT GROUP_CONCAT(a.id ORDER BY a.id SEPARATOR ',')
                     FROM authors a, author_books ab
                     WHERE a.id = ab.author_id
                     AND ab.book_id = b.id) author_id,
                    (SELECT GROUP_CONCAT(concat(a.last_name, ', ', a.first_name)
                     ORDER BY a.last_name, a.first_name SEPARATOR ' & ')
                     FROM authors a, author_books ab
                     WHERE ab.author_id = a.id
                     AND ab.book_id = b.id) author_name,
                     b.id book_id,
                     b.title,
                    (SELECT ROUND(AVG(s.score), 1) FROM scores s WHERE s.item_id = b.id AND media_type_id = 1) rating,
                    b.series,
                    b.part,
                    b.released,
                    g.id genre_id,
                    g.genre,
                    f.id format_id,
                    f.format,
                    CASE series
                    	WHEN 'Standalone' THEN b.released
                    	ELSE (SELECT MIN(bi.released) FROM books bi WHERE bi.series = b.series)
                   	END series_started,
                    bc.user_id
                FROM authors a,
                    books b,
                    genres g,
                    formats f,
                    book_collections bc
                WHERE b.genre_id = g.id
                AND   b.format_id = f.id
                AND   b.id = bc.book_id"
            );
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        DB::statement('DROP VIEW IF EXISTS book_collection_views');
    }
}

Then just create your model like normal and then you can filter, sort and do whatever you like with the data. The good thing about doing it this way is that you can tri, the SQL for performance and will run just one query in you controller/view.

I also keep my Eloquent eloquent so to say.

BookCollectionView::whereUserId($user->id)
            ->orderBy('author_name')
            ->orderBy('series_started')
            ->orderBy('part')
            ->orderBy('released')
            ->orderBy('title')
            ->get(),
            'user' => $user]);
Activity icon

Replied to Can't Use Where Clause After Union Of 2 Queries

When doing unions I that needs to be filtered I do something like this

SELECT column1, 'books'
FROM books
UNION ALL
SELECT column1, 'games'
FROM games

Now I can either put my where clause in both to filter out the desired value like this

SELECT column1, 'books'
FROM books
WHERE released > sysdate
UNION ALL
SELECT column1, 'games'
FROM games
WHERE released > sysdate

Or I wrap the two queries into one like this

SELECT * FROM
	(SELECT column1, 'books', released
	FROM books
	UNION ALL
	SELECT column1, 'games', released
	FROM games)
WHERE released > sysdate

In most cases I most likely end up with the second approach since I then can order and or limit the data from both tables.

I hope this helps you solve your issue.

Sep
24
3 days ago
Activity icon

Replied to Update To Laravel 8 Breaks Login

Thanks @jlrdw not entierly the correct answer but it helped me find the issue. The make:auth generated controllers still referenced App\User so when I updated this to App\Models\User it started working again.

Activity icon

Started a new Conversation Update To Laravel 8 Breaks Login

A couple of weeks ago when Laravel 8 was released I upgraded my project and spent hours on fixing tests and factories and got my so far 400+ tests to green.

Since I've been developing this for a while I have used both the old make:auth and the laravel/ui make:auth to handle the stuff needed for all authentication stuff.

So after I moved all the models to the new Model directory all with passing tests, I wanted to test some stuff manually to see what I would need to do next.

And to my suprise I can't log in!! It throws a nasty error at me that App\User can't be found and I'm like of course not and checks my User model to make sure I have the correct namespace which I do.

Class '\App\User' not found 

This seems to be the culprit

Illuminate\Auth\EloquentUserProvider::createModel
vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php:183

in the method createModel

public function createModel()
{
	$class = '\'.ltrim($this->model, '\');

	return new $class; //line 183
}

Now does anyone have a tip on how to get this to work without making a cusom update to the EloquentUserProvider file?

I rather not start from scratch and spend several hours on copy pasting the code into a new project.

Activity icon

Replied to Errno: 150 "Foreign Key Constraint Is Incorrectly Formed"

Make sure that you use the same type on the ID and the foreign key on all your constraints.

You should use $table->id(); and $table->unsignedBigInteger('<your foreign key field>');

Or the newer syntax

https://laravel.com/docs/8.x/migrations#foreign-key-constraints

Sep
20
1 week ago
Activity icon

Replied to Laravel 6 And Laravel 8

Just make sure you have the correct php version installed and as Snapey said use virtual hosts.

https://royalcode.eu/en/how-to-configure-virtual-host-in-xampp/

Sep
19
1 week ago
Sep
18
1 week ago
Activity icon

Replied to Loop Through Array Json

What do you mean by "Can't access the response"?

Anyways I'd use a forEach on it instead like this.

let data = [
{ 
	"cover_photo": '',
	"alt_description": "pea pods",
	"categories": [],
	"color": "#37510D",
	"created_at": "2018-07-17T16:04:26-04:00"
 }
];



data.forEach((item) => {
	console.log(item.color);
});
Activity icon

Replied to Secure .env

Make sure that the .env is not owned by root.

It should be owned by the user/group that your webserver runs with.

Sep
14
1 week ago
Activity icon

Replied to What Do You Use For Making Your Templates

If you are looking for free software I suggest VS Code. If you are willing to pay it I recommend Phpstorm.

Activity icon

Replied to Mysql Database Views In Laravel

Check my reply in this thread and see how the migration for the view is created.

https://laracasts.com/discuss/channels/laravel/controller-code-vs-model

Sep
08
2 weeks ago
Activity icon

Replied to Perfomance Getting Slower And Slower After Few Thousand Record

Are you using Database transactions? If not try enable it and do a commit every 1000 records or so.

Activity icon

Replied to Perfomance Getting Slower And Slower After Few Thousand Record

I would let the database handle the conversion and leave php out of the equation.

This link has one possible solution

https://stackoverflow.com/questions/27573468/copying-data-from-one-table-to-another-different-column-names

Sep
07
2 weeks ago
Activity icon

Replied to TDD How Do You Test Backend And Frontend

Yes I would most likely write tests like

  • an_admin_can_update_blog_post
  • an_editor_can_update_blog_post
  • a_user_cant_update_a_blog_post

If all user type can update the post I would write one test that asserts that they can

  • any_user_can_update_a_blog_post
Sep
06
3 weeks ago
Activity icon

Awarded Best Reply on Jquery Td To Javascript Td

This should help you with the prevent default

https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault

You should also be able to use the event's target to determine what has been clicked.

https://developer.mozilla.org/en-US/docs/Web/API/Event/target

Too bad I'm on a two week vacation otherwise I have code at work that I bellieve does what you need.

Activity icon

Replied to TDD How Do You Test Backend And Frontend

When it comes to the frontend I only test that certain things are present or not present.

Something like this

   /**
     * @test
     */
    public function user_can_create_authors()
    {
        $this->signIn();

        $response = $this->get('/authors/create');

        $response->assertSee('name="first_name"', false);
        $response->assertSee('name="last_name"', false);
        $response->assertSee('name="_token"', false);
        $response->assertSee('input type="submit" value="Save"', false);
    }

and something like this

/**
     * @test
     */
    public function after_creating_an_author_the_user_is_redirected_to_the_authors_index_view_and_success_message_is_shown()
    {
        $this->signIn();
        $author = factory(Author::class)->make();

        $response = $this->post('/authors', $author->toArray());

        $response->assertStatus(302);
        $response->assertLocation('/authors');

        $response = $this->get('/authors');
        $response->assertSee($author->name . ' successfully added.');
    }

To test the functionality I suggest using Cypress

https://www.cypress.io/

Activity icon

Replied to More Table Confusion

You can simply do

$events = Event::with('user')->get();

Then you will the user associated with the event

Read more here

https://laravel.com/docs/7.x/eloquent-relationships#eager-loading

Sep
04
3 weeks ago
Activity icon

Replied to Overwhelmed With Templating And Front-end Frameworks. Help Me Out

I would say it all depends on what you are trying to do in your app.

My thoughts is somethng like this

  • Simple crud = Only blade
  • Crud with more advanced layout = Blade & blade components
  • Crud with required ajax = Blade + Vanilla Javascript
  • Javascript heavy crud = Blade + desired javascript library (Vue, Alpine, Angular, React or whaterver else)
  • Complex webapp beyond crud = Any of the above mentioned frameworks.
Aug
31
3 weeks ago
Activity icon

Replied to Cant Upgrade Php Version On MacOS Catalina

Try this command

brew unlink php && brew link [email protected]

Then restart all your php and nginx.

Aug
29
4 weeks ago
Activity icon

Awarded Best Reply on Customize Increment Arrows On Input Of Type Number Using CSS

When you have more than one you need pass the element in question otherwise it will just use the one I hardcoded in.

let number = document.querySelector('[name="number"]');

You can do something like this

<div>
  <button onclick="dec('qty')">-</button>
  <input name="qty" type="text" readonly value="0">
  <button onclick="inc('qty')">+</button>  
</div>

<div>
  <button onclick="dec('amount')">-</button>
  <input name="amount" type="text" readonly value="0">
  <button onclick="inc('amount')">+</button>  
</div>
function inc(element) {
  let el = document.querySelector(`[name="${element}"]`);
  el.value = parseInt(el.value) + 1;
}

function dec(element) {
  let el = document.querySelector(`[name="${element}"]`);
	if (parseInt(el.value) > 0) {
	  el.value = parseInt(el.value) - 1;
  }
}

Check this fiddle

https://jsfiddle.net/62bxcd43/

You can add some more code to handle the range quite easily.

Aug
27
1 month ago
Activity icon

Replied to Design Questions - Address

I would go with just keeping the credentials in the users table and then put the rest in a profiles table. Sure you can stick everything in the users table but that might give you a "god" table. I might even cosider having three tables if the user profile contains other user related data that is not really connected to the user's address. Then like you mentioned I might even have three tables (users/user_profiles/user_addresses).

I personally don't like to have too many fields in a table since it makes

  • The form connected to the table large
  • Makes you pull more data then necessary (every field in the table) with something as easy as $request->user
  • Makes you "always" have to tell which fields you want to get back

One to one relationships is in my opinion a good practice when it makes sense to keep the data isolated.

Activity icon

Replied to Help Correct My Query

A bit more context is needed here.

Are you passing the id into the controller method? Or are we talking about the authenticated user?

On the second you can either use

Auth::user()->id

or

$request->user->id

to get the current user.

Activity icon

Awarded Best Reply on Best Way To Implement Product Attributes

Depending a bit on how you have set up the other tables but I would most likely create a product_attributes table.

It would look something like this

  • id
  • product_id (references id in the product table)
  • attribute_name
  • attribute_value

So a product with a single attribute would look like this

1, 1, color, yellow

One with multiple attributes would look like this

1, 1, color, blue
2, 1, height, 20cm
3, 1, diameter, 5"
Aug
26
1 month ago
Activity icon

Awarded Best Reply on Laravel Features To Avoid/deprecated?

It's not deprecated so it's up to you if you prefer the array syntax for routes. I haven't seen the breaking changes in laravel 8 yet but I doubt they will deprecate the route syntax.

Route::get('records', [
    'uses' => '[email protected]',
    'as' => 'records.index'
]);

Or you can choose to write it like this

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

Or as a resource

Route::resource('records', 'RecordsController');

There are more ways to write these as well, it't up to you to choose the one you prefer. I use the last two mostly since they are in my opinion cleaner.

Activity icon

Replied to Best Way To Implement Product Attributes

Depending a bit on how you have set up the other tables but I would most likely create a product_attributes table.

It would look something like this

  • id
  • product_id (references id in the product table)
  • attribute_name
  • attribute_value

So a product with a single attribute would look like this

1, 1, color, yellow

One with multiple attributes would look like this

1, 1, color, blue
2, 1, height, 20cm
3, 1, diameter, 5"
Activity icon

Awarded Best Reply on Querying Users Freezes Application - Nova

I guessing you pull the complete user from the database then do your processing. Try just pulling the id and the username instead.

Activity icon

Replied to Laravel Features To Avoid/deprecated?

It's not deprecated so it's up to you if you prefer the array syntax for routes. I haven't seen the breaking changes in laravel 8 yet but I doubt they will deprecate the route syntax.

Route::get('records', [
    'uses' => '[email protected]',
    'as' => 'records.index'
]);

Or you can choose to write it like this

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

Or as a resource

Route::resource('records', 'RecordsController');

There are more ways to write these as well, it't up to you to choose the one you prefer. I use the last two mostly since they are in my opinion cleaner.

Aug
24
1 month ago
Activity icon

Replied to Merging 4 Databases

To get that custom importer to work will take longer time than doing it manually.

Activity icon

Replied to Merging 4 Databases

It's tricky and would most likely involve lots of temporary tables.

However something like this should work

  1. Export table 1 from DB1
  2. Import it as table_db1
  3. Repeat for all tables and DBs
  4. Insert table_db1, table_db2, table_db3 & table_db4 into table
  5. Use the _db tables to help you get the correct relations on the other tables referencing one or more foreign keys.
Aug
23
1 month ago
Activity icon

Replied to User Role Tables

Remove it and create a method on the user model called is doctor that checks the existence of the user id in the doctors table.

Activity icon

Replied to Foreign Key Problems In User Table

The user table should not have the

$table->foreignId('doctor_id')->references('id')->on('doctors')->onDelete('cascade');

Move that to the doctors table instead

Schema::create('doctors', function (Blueprint $table) {

        $table->id();
	$table->foreignId('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->timestamps();
    });
Activity icon

Replied to User Role Tables

I don't know why you've added the boolean if you are not going to use it.

The doctors table or rather roles table that way you could add nurses at a later point, could look something like this

$table->id();
$table->foreignId('user_id')->constrained();
$table->string('role');
$table->timestamps();
Activity icon

Replied to What Is A Minimal Way To Audit A Database Table/entry?

You are talking about a log table. I would create a trigger on the users table that on update saves the old and new values.

it could look something like this.

  • id
  • table
  • old_value
  • new_value
  • updated_by
  • updated_at

https://www.mysqltutorial.org/mysql-triggers/mysql-after-update-trigger/

Activity icon

Replied to I Need Equivalent Eloquent Query

You can use whereIn

$users = DB::table('users')
                    ->whereIn('id', [1, 2, 3])
                    ->get();

and havingRaw

$orders = DB::table('orders')
                ->select('department', DB::raw('SUM(price) as total_sales'))
                ->groupBy('department')
                ->havingRaw('SUM(price) > ?', [2500])
                ->get();

and subqueries

$users = User::where(function ($query) {
    $query->select('type')
        ->from('membership')
        ->whereColumn('user_id', 'users.id')
        ->orderByDesc('start_date')
        ->limit(1);
}, 'Pro')->get();

All the code examples are from the docs.

https://laravel.com/docs/7.x/queries

Activity icon

Replied to Need Help On Creating Transaction Tracker System.

If the wallet table contains the amount of money and it's just one type of money then I would store the amount in the table and update it according to any transactions. If it contains different types of monetary records like credit, mortages, stocks and so on I would most likely not do that. The transactions table is just a tracker imho to keep track of where the money is transfered or received from.

When working with money I suggest you use Database Transactions to make sure everything has been processed successfully before commiting the change.

Activity icon

Awarded Best Reply on Laravel Versions

This is just a theory of mine but since Laravel 6 and 7 require a higher version of php it might cause some not to switch up. It could also be that like you said most tutorials use Laravel 5.x, while the differences are not huge between 5, 6 and 7 they are big enough to make it a little bit harder to follow a tutorial.

I would go with the latest version and look at the docs on the upgrade guide to see the changes between each version.

https://laravel.com/docs/7.x/upgrade

Activity icon

Replied to Laravel Versions

This is just a theory of mine but since Laravel 6 and 7 require a higher version of php it might cause some not to switch up. It could also be that like you said most tutorials use Laravel 5.x, while the differences are not huge between 5, 6 and 7 they are big enough to make it a little bit harder to follow a tutorial.

I would go with the latest version and look at the docs on the upgrade guide to see the changes between each version.

https://laravel.com/docs/7.x/upgrade

Aug
22
1 month ago
Activity icon

Replied to Customize Increment Arrows On Input Of Type Number Using CSS

When you have more than one you need pass the element in question otherwise it will just use the one I hardcoded in.

let number = document.querySelector('[name="number"]');

You can do something like this

<div>
  <button onclick="dec('qty')">-</button>
  <input name="qty" type="text" readonly value="0">
  <button onclick="inc('qty')">+</button>  
</div>

<div>
  <button onclick="dec('amount')">-</button>
  <input name="amount" type="text" readonly value="0">
  <button onclick="inc('amount')">+</button>  
</div>
function inc(element) {
  let el = document.querySelector(`[name="${element}"]`);
  el.value = parseInt(el.value) + 1;
}

function dec(element) {
  let el = document.querySelector(`[name="${element}"]`);
	if (parseInt(el.value) > 0) {
	  el.value = parseInt(el.value) - 1;
  }
}

Check this fiddle

https://jsfiddle.net/62bxcd43/

You can add some more code to handle the range quite easily.

Activity icon

Replied to Customize Increment Arrows On Input Of Type Number Using CSS

It's always tricky to style forms elements and the number element is not properly supported by all browsers yet. So I woul most likely create a text field surrounded by two buttons and handle it with some javascript. Then I can style each element on it's own.

Something like this

<div>
  <button onclick="dec()">-</button>
  <input name="number" type="text" readonly value="0">
  <button onclick="inc()">+</button>  
</div>
function inc() {
  let number = document.querySelector('[name="number"]');
  number.value = parseInt(number.value) + 1;
}

function dec() {
  let number = document.querySelector('[name="number"]');
	if (parseInt(number.value) > 0) {
	  number.value = parseInt(number.value) - 1;
  }
}
Activity icon

Replied to About "How To Build Modular Applications In Laravel" Articles

Why don't you ask the author if he has any plans on creating part three directly instead of asking the question here?

https://twitter.com/DestinyAjax