boby

boby

Member Since 6 Months Ago

Experience Points
1,460
Total
Experience

3,540 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
8
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
1,460 XP
Mar
29
1 day ago
Activity icon

Replied to Barryvdh/laravel-dompdf Table Page Break Problem

Perfect! Works like a charm :)

@if($loop->iteration == 13)
	</tbody>
</table> <!-- Table closed -->
<div class="page-break"></div> <!-- Page break -->
<table class="table invoice-articles-table">
	<thead>
		<tr>
			<th>#</th>
			...
	</thead>
	<tbody>
@endif

Is there a better way to break than this "manual" on line 13? I am counting here manually, but is there some better way, which will use as much space as possible, which won't break if I change some css (e.g. row height)?

Thank you!

Activity icon

Started a new Conversation Barryvdh/laravel-dompdf Table Page Break Problem

Hi,

so I am using barryvdh/laravel-dompdf to generate invoice table, but the problem is on page break.

css:

.page-break {
page-break-before: always;
}

in my blade file:

<tbody>
	@foreach($invoice->articles as $article)
		<tr>
			<td>
	  			{{ $loop->iteration }} 
	  		</td>
	  		<td>
	  			{{ $article->name }} 
	  		</td>
	  		<td>
	  			{{ $article->quantity }} 
	  		</td>
			...
	  	</tr>
	  	@if($loop->iteration == 13)
	        	<div class="page-break"></div>
	        @endif
	  @endforeach
</tbody>

I am braking table after 13 items, and everything is fine, but the row on item 14 is screwed because of this div I assume:

https://www.dropbox.com/s/aupu3tu4wwx2yel/Screenshot_20200329_115614.png?dl=0

Mar
13
2 weeks ago
Activity icon

Replied to Ajax Array Of Objects To DB

I was thinking to do it that way with time function, but I didn't know that insert don't add timestamps, but it makes sense.

Laravel way or not, I wouldn't think of mapping ever.

Thank you once again.

Activity icon

Replied to Ajax Array Of Objects To DB

Works! Thanks! You had typo $Invoice should be $invoice. :)

My timestaps are not updated, why is that? created_at & updated_at?

Thank again, but second question is, what did this mapping do? Isn't there laravel build in functionality to do this directly

Activity icon

Replied to Ajax Array Of Objects To DB

No :D Will try now

Activity icon

Replied to Ajax Array Of Objects To DB

I tried to put dd, nothing happens, I get error 500 on view page in console and in telescope I see the above error

Activity icon

Replied to Ajax Array Of Objects To DB

Can't use dd as it doesn't "die", it returns back to view cause of ajax. But i have telescope installed, where I track my requests. Can I do it differently?

Activity icon

Started a new Conversation Ajax Array Of Objects To DB

Hi, I am little stuck :)

I am sending this from my view to my controller via ajax:

{
	"number": "0001/2020",
	"title": "Test invoice 1",
	"customer_id": "1",
	"invoice_date": "2020-03-13",
	"articles": [
		{
			"name": "article1",
			"price": "55.99",
			"quantity": "1",
			"total": "55.99"
		},
		{
			"name": "article2",
			"price": "44.99",
			"quantity": "2",
			"total": "89.98"
		}
	]
}

in my controller I save invoice like this:

        $attributes = $this->validateInvoice();
        $attributes['user_id'] = Auth::user()->id;
        $articles = $attributes['articles'];

        foreach ($articles as $article) {
             $attributes['total'] += (float)($article['total']);
        }        
        $invoice = Invoice::create($attributes);

and this is saved ok in DB.

now I want to save articles in other table:

        $articles = $articles->toArray();
        $articles['invoice_id'] = $invoice->id;
        InvoiceArticle::insert($articles);

but this throws:

Call to a member function toArray() on array

My $articles are array, but array of objects, not array of arrays.

Jan
19
2 months ago
Activity icon

Replied to Multi Validation For Number

This looks like exactly what i need :)

Will try it, thx a lot!

Activity icon

Started a new Conversation Multi Validation For Number

Hi,

In my app, I am using books ISBN number which can be 10 or 13 digits. I also gave possibility to leave it blank. My validation is like this:

        $attributes['isbn'] = request('isbn') ? request('isbn') : NULL;
        if($attributes['isbn']) {
            request()->validate([
                'isbn'   => ['numeric','digits: 13']
            ]);
        }

Is it possible to make rule that isbn must be exactly 10 digits or exactly 13 digits or NULL? I did it for NULL and 13 digits but don't know how to make it for 10 digits as well.

Dec
26
3 months ago
Activity icon

Replied to Request()->validate Not Stopping Script

Well, that worked. Could you please tell me what is the difference using closure and my way?

Thx!

Activity icon

Started a new Conversation Request()->validate Not Stopping Script

I have in my web.php

Route::get('changePassword', '[email protected]')->name('changePassword')->middleware('auth');
Route::patch('updatePassword', '[email protected]')->name('updatePassword')->middleware('auth');

and my code in UserController is:

public function changePassword()
    {
        $user = User::findOrFail(Auth::user()->id);
        return view('users.change_password', compact('user'));
    }

    public function updatePassword(Request $request)
    {
        $user = Auth::user();

        $attributes = request()->validate([
            'password' => ['required', 'string', 'min:8', 'confirmed', 'different:current_password'],
            'current_password' => ['required', function () {
                if (!Hash::check(request('current_password'), Auth::user()->password)) {
                    return redirect($this->redirectPath())->with('error', 'The current password is incorrect.');
                }
            }],
        ]);

        $user->fill(['password' => Hash::make(request('password'))])->save();
        return redirect($this->redirectPath())->with('success','Password changed successfuly.'); 

    }

    public function redirectPath()
    {
        $role = Auth::user()->role;
        
        switch($role) {
            case '1':
                return '/admin';
                break;
            case '2':
                return '/books';
                break;
            case '3':
                return '/home';
                break;
            default:
                return '/login';
                break;
        }
    }

the problem is after change password (I put wrong old password ), I have both messages:

First: Password changed successfuly. And after it: he current password is incorrect.

what a hell? Like password is changed first and then it catches that the old one is wrong!

Nov
01
4 months ago
Activity icon

Replied to Table Search Laravel

Hi,

I managed to get jquery to work after removing "defer" from my app.js include, which was there by default!

<script src="{{ asset('js/app.js') defer }}"></script>

Now my search is working and this is how I did it:

app.blade.php

 <!-- Scripts -->
 <script src="{{ asset('js/app.js') }}"></script>
 <script src="{{ asset('js/jquery.dataTables.min.js') }}"></script>

<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<link href="{{ asset('css/override.css') }}" rel="stylesheet">

Additional files I downloaded to my public/css and public/js foders. Downloaded from CDNs.

And then in my blade file were I need search:

<script>
    $(document).ready(function() {
        $('#users-table').DataTable();
    });
</script>
Oct
27
5 months ago
Activity icon

Replied to Table Search Laravel

Ok, I give it a try. Thx

Activity icon

Replied to Table Search Laravel

I am adding css and js files in layouts/app.blade.css file. I also tried to add them directly to blade file where my table is. I guess I need to read more about webpack, as I don't know how all this works.

But how do I activate jquery ? Do I have it based on what is written in package.json? How do I add custom js files like "https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"? and how to compile it?

Activity icon

Replied to Table Search Laravel

And I said without manually adding so many files, didn't mean these from package.json

Activity icon

Replied to Table Search Laravel

But what does this mean?

"jquery": "^3.2",

is the jquery loaded then? If yes, why is my script throwing error "$(document).ready(function() {" is not defined

Activity icon

Replied to Table Search Laravel

I already did all that, npm install and npm run dev. I checked my package.json file:

"devDependencies": {
        "axios": "^0.19",
        "bootstrap": "^4.0.0",
        "cross-env": "^5.1",
        "jquery": "^3.2",
        "laravel-mix": "^4.0.7",
        "lodash": "^4.17.13",
        "popper.js": "^1.12",
        "resolve-url-loader": "^2.3.1",
        "sass": "^1.15.2",
        "sass-loader": "^7.1.0",
        "vue-template-compiler": "^2.6.10"
    },
    "dependencies": {
        "@jkryszto/mdb-for-laravel": "^1.0.0"
    }

as you can see at the end I also have that MDB I mentioned in my first post.

Activity icon

Replied to Table Search Laravel

And yes, when I try this examples outside of laravel it works ofc. :(

Activity icon

Started a new Conversation Table Search Laravel

I am looking for solution on the internet and this forum, but just can't make it work. I have a table with books and I want to add "search" functionality for title's and author's on that table.

I have tried "https://mdbootstrap.com/docs/jquery/tables/search", but I end up with adding duplicate libraries like bootstrap.min.css or jquery.js, which is already in laravel, as I can see in package.json file, and also I think that is not a proper way to do this. But anyway, search don't work even with all this files.

I have also tried to install MDB with npm, and everything is ok with inststall, but there is no search added to my table. This is also what I tried: "https://datatables.net/examples/basic_init/zero_configuration.html", but there is a error that "$(document).ready(function() {" is not defined! Like jquery is not there at all!

Am I missing something here, that 3 tutorials are not working? Do I need somehow activate jquery and other stuff or it is already activated with laravel?

Is there any easy way to do this, without adding so many js and css files? Or if I have to add them, how can I add only one's that I don't have in laravel by default? I would like some clean and easy solution. And yes, search must be "on fly", without re-fetching data from database. :)

Sry for such a long post, but I speed few days with no progress.

Oct
13
5 months ago
Activity icon

Replied to Forcing A Unique Rule To Ignore A Given Id Proper Way

If I remove my $id then I have error Undefined property: App\Http\Controllers\UserController::$user for:

'username' => ['required', 'string','min:3', 'max:255', Rule::unique('users')->ignoreModel($this->user)],
Activity icon

Replied to Forcing A Unique Rule To Ignore A Given Id Proper Way

what "Rule" should I import?

in

public function update(UpdateUserRequest $request, User $user) 

I need my $id parameter as well. If I do this:

public function update(Request $request, $id, User $user)

then I have error to many arguments

Activity icon

Replied to Forcing A Unique Rule To Ignore A Given Id Proper Way

web.php:

Route::resource('users', 'UserController');
Auth::routes();

and UserController:

<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;

class UserController extends Controller
{
    public function index()
    {
    //not relevant
    }

    public function create()
    {
        return view('users.create');
    }

    public function store(Request $request)
    {
        $attributes = $this->validateUser();

        $user = User::create($attributes);
    
        return redirect ('/users')->with('success','User added successfully.');
    }

    public function show($id)
    {
        //not relevant
    }

    public function edit($id)
    {
        $user = User::find($id);
        return view('users.edit', compact('user));
    }

    public function update(Request $request, $id)
    {
        $attributes = $this->validateUser();
        
        $user = User::find($id)->update($attributes);

        return redirect ('/users')->with('success','User changed successfully.');        
    }

    public function destroy($id)
    {
        //
    }

    protected function validateUser()
    {
        $rules = [    
            'username' => ['required', 'string','min:3', 'max:255', 'unique:users'],
            'first_name' => ['required', 'string','min:3', 'max:255'],
            'last_name' => ['required', 'string','min:3', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
            'date_of_birth' => ['required', 'date'],
            'image'  => ['image','mimes:jpeg,png,jpg,gif,svg','max:4098',
                        'dimensions:min_width=250,min_height=350',
                        'dimensions:max_width=1200,max_height=1500'],            
        ];

        if (! $this->user) {
            $rules['username'] = ['required', 'string', 'min:3', 'max:255'];
            $rules['email'] = ['required', 'string', 'email', 'max:255'];
        }

        return request()->validate($rules);

    }
}
Activity icon

Started a new Conversation Forcing A Unique Rule To Ignore A Given Id Proper Way

I saw there is a 15+ threads about this, but I just can't get it work!

This is my validation for user create and edit:

protected function validateUser()
    {
        $rules = [    
            'username' => ['required', 'string','min:3', 'max:255', 'unique:users'],
            'first_name' => ['required', 'string','min:3', 'max:255'],
            'last_name' => ['required', 'string','min:3', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
            'date_of_birth' => ['required', 'date'],
            'image'  => ['image','mimes:jpeg,png,jpg,gif,svg','max:4098',
                        'dimensions:min_width=250,min_height=350',
                        'dimensions:max_width=1200,max_height=1500'],            
        ];

        if (! $this->user) {
            $rules['username'] = ['required', 'string', 'min:3', 'max:255'];
            $rules['email'] = ['required', 'string', 'email', 'max:255'];
        }

        return request()->validate($rules);

    }

So I want to ignore id of a current user for a username and email. I have also tried:

...
'username' => ['required', 'string','min:3', 'max:255', 'unique:users,' . $id]
...

but that can't find $id ofc as it is not passed to function.

First method complains about Undefined property: App\Http\Controllers\UserController::$user

I just don't know how to make this work

Oct
07
5 months ago
Activity icon

Replied to Method Destroy() Not Picking Up ID

I have models: Book, Owe and User. Controllers: BooksController, OwesController,UserController. Note that first two are plural, while UserController is not.

route:list show this line:

owes/{owe}       | owes.destroy     | App\Http\Controllers\[email protected]

and for the book:

books/{book}    | books.destroy    | App\Http\Controllers\[email protected]

Now tell me please why on books destroy method I have:

public function destroy(Book $book)

and on owe destroy method I have:

public function destroy($owe)

they are not the same. That confuses me, what are the rules for parameters when resource is used for controllers.

Oct
06
5 months ago
Activity icon

Replied to Method Destroy() Not Picking Up ID

I am aware of route:list, but still this is not clear to me.

E.g. my book destroy method looks like this:

public function destroy(Book $book)

while destroy for Owe looks like this:

public function destroy($owe)

and owe and book are not my model names.

Sorry for complicating this, but I am just trying to understand how this works, as it look like that I don't know. :(

Activity icon

Replied to Method Destroy() Not Picking Up ID

Ok, that worked! Could you tell me why, how? :)

Activity icon

Replied to Method Destroy() Not Picking Up ID

Hi geowrge, this is my web .php:

Route::resource('owes', 'OwesController');

so I am trying to use default approach like on other controllers and that is action="owes/{{$owe->oweId}}" but I don't know how to get this oweId on destroy method.

Activity icon

Replied to Method Destroy() Not Picking Up ID

Hey man, thx for answer. I believe that bracket was typo. At this stage (before submit) I have ID, e.g.:

/owes/12

but once in destroy method, I don't have it, it is null. I'll try once more.

For the user, the thing is, I don't want ID from the logged in user, but the ID from the user that this book is rented to. This is how I list rented books:

@foreach($owes as $owe)
    <div class="row owe-row">
        <div class="col-4 owe-row-content"> 
            {{ $owe->title }} - <i> {{ $owe->first_name }} {{$owe->last_name}}</i> 
        </div>
        <div class="col owe-row-button">
            <form method="POST" action="{{ route('owes.destroy', $owe->oweId) }}">
                @method('DELETE')
                @csrf
                <input type="hidden" name="member" value="{{ $owe->userId }}">
                <button type="submit" class="btn btn-primary">
                            {{ __('Return book') }}
                    </button>
            </form>
        </div>
    </div>                          
@endforeach 
Activity icon

Started a new Conversation Method Destroy() Not Picking Up ID

So, I am working on something that should be like online books library. I have controllers Books and Users, and one as a relation between them, called OweController. I use CRUD on this controllers. When I navigate to Owes page I fill it like this:

public function index()
    {
        $owes = Owe::where('owes.active', '1')
                    ->leftjoin('books','owes.book_id', '=', 'books.id')
                    ->leftjoin('users','owes.user_id', '=', 'users.id')
                    ->select('owes.id as oweId', 'books.id as bookId','books.title','users.id as userId','users.first_name','users.last_name')
                    ->get();

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

then on index I have a form for book return:

<form method="POST" action="{{ route('owes.destroy', $owe->oweId) }}">
@method('DELETE')
@csrf
    <input type="hidden" name="member" value="{{ $owe->userId }}">  
        <button type="submit" class="btn btn-primary">
                {{ __('Return book') }}
            </button>
</form>

So question: if I use as above: route('owes.destroy', $owe->oweId) my destroy method picks this oweId as:

public function destroy($oweId)
{
        $owe = Owe::findOrFail((int)($oweId));
        $owe->update(['active' => false]);
    ...

but if I do it like on other controllers using: action="/owes/$owe->oweId) - this oweID is sent to destroy but not picked up from it. It is null. Of course my destroy is different in that case: destroy(Request $request, Owe $owes)

Second question is, can I send userId without using hidden in above form as I think that is not a proper way to do it.

So sorry for such a long post, but I wanted to provide as much info as possible.