Tomasz_Ek

Tomasz_Ek

Member Since 1 Month Ago

Experience Points
2,200
Total
Experience

2,800 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
0
Lessons
Completed
Best Reply Awards
3
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,200 XP
May
02
4 weeks ago
Activity icon

Replied to Route Not Defined

Check also :

php artisan route:list

To be sure about your routes. You can also wrap route('droids.index') in {!! /* code */ !!} to prevent errors.

Activity icon

Replied to Route Not Defined

Maybe its becouse your middleware ? In app.blade.php I see you use @can directive but in second part you don't. Maybe your user can't see droids ?

May
01
1 month ago
Activity icon

Replied to ErrorException (E_NOTICE) Undefined Variable: BookId

Another example which can help you understand your problem:

function test() {
	 throw new Throwable();
	 return 1;
 }

 try {
	 $book_id = test();
	 print $book_id;
 } catch (\Throwable $e) {
	 print $book_id;
 }

$book_id should get value from test() but test causing error so $book_id in catch is undefined.

Activity icon

Replied to ErrorException (E_NOTICE) Undefined Variable: BookId

It isn't true that variable is invisible in catch scope. You can test my previose code. It's work in both scopes. But if you do something like this:

try {
	$book_id;
	print $book_id;
	throw new Throwable();
} catch (\Throwable $e) {
	print $book_id;
}

It throw error Undefined variable. becouse variable is undefined in try scope.. so it's also undefined in catch scope.

Activity icon

Replied to ErrorException (E_NOTICE) Undefined Variable: BookId

It's highly likely that the command:

DB::table('books')->insertGetId([...])

causing error. Becouse it doesn't work properly it's throwing an error, but it's nothing written into $bookId. If the error were to be thrown later, everything would be fine and in the $ bookId variable there would be value. Test this example and see that it works fine until the error is thrown before or in line with the variable $ book_id.

try {
	 $book_id = 1;
	 print $book_id;
	 throw new Throwable();
 } catch (\Throwable $e) {
	 print $book_id;
 }

Check again insertGetId function.

Use getMessage() function on thrown error and check what is the reason.

Apr
26
1 month ago
Activity icon

Replied to Binding In Nested Select.

It was something wrong with my scope approval.. When I replaced this:

->approval()->select([...])

into this:

->select([...])->approval()

everything work just great. Thanks for help :D

Activity icon

Replied to Binding In Nested Select.

My mistake.. I forgot to add ] on the end.. but it's seems to not working couse every users have 0 points which is not true. If I type "2020-04-__" first user have 40 points, but when I use bindings it's show he have 0.

Activity icon

Replied to Binding In Nested Select.

stripos() expects parameter 1 to be string, array given

Activity icon

Started a new Conversation Binding In Nested Select.

How to bind variables into this:

User::approval()
->select('id', 'name', 'surname', DB::raw('(SELECT IFNULL(SUM(point), 0) FROM points WHERE points.id = users.id AND points.date LIKE "?-?-__") as points'))
->orderBy('points', 'desc')
->limit($limit)
->offset($offest)
->get();

I want to bind year and month from params in URL. Laravel version 5.8.35.

Apr
25
1 month ago
Activity icon

Started a new Conversation Repeatable Code In The Controller.

I have controller with about 7 methods .. all for diffrent views and datas. But in all I have part of code with repeat. Something like this:

$states = array("pageA" => false, "pageB" => false );
if ( App\Config::getOriginal('pageA') == 1 ) {
	$status["pageA"] = true;
} else if ( App\Config::getOriginal('pageB') == 1 ) {
	$status["pageB"] = true;
} 

etc.

It's about 20 lines one code in 7 methods with give 140 lines of code.. how can I avoid it?

Activity icon

Awarded Best Reply on Composer Does Nothing.. Failed Open Stream

Emm.. this work for me:

sudo sh -c "echo 'precedence ::ffff:0:0/96 100' >> /etc/gai.conf"

After 5.5h fight with linux I going to cry.. from happiness.. becouse it's work now :3

Activity icon

Replied to Composer Does Nothing.. Failed Open Stream

Emm.. this work for me:

sudo sh -c "echo 'precedence ::ffff:0:0/96 100' >> /etc/gai.conf"

After 5.5h fight with linux I going to cry.. from happiness.. becouse it's work now :3

Activity icon

Replied to Composer Does Nothing.. Failed Open Stream

php -v

PHP 7.4.5 (cli) (built: Apr 15 2020 17:14:40) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies

composer config disable-tls false

doesn't change anything :(

Activity icon

Started a new Conversation Composer Does Nothing.. Failed Open Stream

Linux arch. Composer installed by : pacman -S compsoer

I try:

compsoer create-project why-is-this-doesnot-workin-cry

or:

composer global require laravel/installer

or:

composer diagnose

or:

enything else...

but I always get:

[Composer\Downloader\TransportException]

The "https://repo.packagist.org/packages.json" file could not be downloaded: failed to open stream: Connection timed out

Apr
12
1 month ago
Activity icon

Replied to Serial Key Generator - Random String With Separators.

uuid is e little bit to long. I need something shorter as a key for new users which want to register. They can register only if they hava a key :D

Activity icon

Started a new Conversation Serial Key Generator - Random String With Separators.

Is there an easy way to change this:

Str::random(20) // e.g 4O3i7JDV9Em6qSqtL1SH

into this:

4O3i-7JDV-9Em6-qSqt-L1SH

Apr
11
1 month ago
Activity icon

Replied to Two Controllers For Same Model - Best Practices ?

Maybe should I create one index() method with param $active or something like this?

Activity icon

Started a new Conversation Two Controllers For Same Model - Best Practices ?

Refactoring the old project and I wonder how to do it best:

I have users in the database who have an active field. In the admin panel I have two subpages "active users" and "inactive users". Two ActiveUsersController and InactiveUsersController were created in the project.

In the first is the method:

public index () { $users = User :: activeUsers () ..etc }

and in the second:

public index () { $users = User :: inactiveUsers () ..etc }

where activeUsers and inactiveUsers are the scopes defined in the model.

I suppose both controllers should be marged into one. Is there any suggested "best" option?

Apr
08
1 month ago
Activity icon

Replied to Uploading Laravel To Server

Server can find path D:\[..]

You probably have static path in some place chcek index.php in public dir or views in resources dir.

Check also your config files.

Activity icon

Awarded Best Reply on Blank Screen

Check the web browser console and look on errors. If is nothing there try to find section with logs on your hosting. I think it can be something with wrong paths or wrong php version on your server..

Apr
07
1 month ago
Activity icon

Replied to Blank Screen

Higher version php on server should work properly.. I know your pain because few weeks ago I have the same issue. In my side it was it that I can't get access to dirs outside public_html. On the end I puted everything into public_html..

Can you show your htaccess from public_html?

Check again if your paths are correct.

Activity icon

Replied to Blank Screen

Check the web browser console and look on errors. If is nothing there try to find section with logs on your hosting. I think it can be something with wrong paths or wrong php version on your server..

Activity icon

Awarded Best Reply on Laravel Collections Get Sub Element

I copied your code and test it on myself. Check again this..

dd($collection->get('options')['value1']);

It's work properly. Can you show all part of the code? Maybe you have a mistake elsewhere?

Let me know if it helped.

Activity icon

Replied to Laravel Collections Get Sub Element

I copied your code and test it on myself. Check again this..

dd($collection->get('options')['value1']);

It's work properly. Can you show all part of the code? Maybe you have a mistake elsewhere?

Let me know if it helped.

Activity icon

Awarded Best Reply on Multiple DB Charset In Laravel Config Database

Try this..

SELECT CONCAT("ALTER TABLE ", TABLE_SCHEMA, '.', TABLE_NAME,' COLLATE utf8_unicode_ci;') FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='DBNAME' AND TABLE_TYPE = 'BASE TABLE';

Apr
06
1 month ago
Activity icon

Replied to Multiple DB Charset In Laravel Config Database

Try this..

SELECT CONCAT("ALTER TABLE ", TABLE_SCHEMA, '.', TABLE_NAME,' COLLATE utf8_unicode_ci;') FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='DBNAME' AND TABLE_TYPE = 'BASE TABLE';

Activity icon

Replied to Multiple DB Charset In Laravel Config Database

Back up the database and change charset of all tables to utf8mb4_unicode_ci. Let me know if it helped.

Activity icon

Replied to One API For Many Databases.

Do you know any good guide to this package? Because in addition to documentation, I wish to see a good example to understand it.

Activity icon

Replied to One API For Many Databases.

Personally I prefer have all tanent in separate db with one API for all, but I also still looking for the best solution..

Apr
05
1 month ago
Activity icon

Replied to One API For Many Databases.

It's also looks intresting https://tenancy.dev/

Activity icon

Replied to One API For Many Databases.

Fortunately, unfortunately I have in contracts that I am the only administrator (actually this is my one-man company), he knows if something goes wrong I have to take all responsibility, but I have the right to devote everything (almost everything: P).

Generally, no one cares what happens on the server side, as long as there is no data leakage.

I will try to add a unit field to each table and decide what to display to whom by this field. What do you think?

Activity icon

Replied to One API For Many Databases.

Maybe I should have one db any separate tables for all tenancy like: db.app_unit1_users db.app_unit2_users And then make authentication not for many db but for many tables.. it seems to be simpler, but it's look ugly for my..

Activity icon

Replied to One API For Many Databases.

Yep. Each request have information about unit. I tried with middleware but it didn't work out as intended. I used the command

Config::set('database.connections.mysql.database', $unit)

..but it didn't seem to work because laravel was constantly throwing that [mysql] is undefined.

I am generally ready for big changes. If there is a better option to prepare applications for many tenants, each of whom has access to their data, please let me know.

Activity icon

Replied to One API For Many Databases.

Maybe I can agree with you that in current situation is stupid. But have you beeter idea? One database is the simplest solution.

But in each database I have a lot of data intended only for users of this database. So how can I combine all the databases into one and not lose this functionality?

I also think that separate databases are more secure, isn't it?

Activity icon

Replied to One API For Many Databases.

Not quite ... indeed, so far each subdomain is a separate instance .. but in my question I want to have one instance, e.g. api.my-app.com and on unit1.my-app.com only have fronted ( React), which sends queries to api. To get the answer he must authenticate and get a token. I just don't know how to do this with many databases. For example, I have 10 databases and 10 users tables, and different users in each .. I am now trying with JWT and guards

Activity icon

Started a new Conversation One API For Many Databases.

Hey. I have an application to which I sell access to a group of customers - paid subscription. Each buyer receives his subdomain and database with many tables. Each buyer provides the key to his subdomain to his employees so that they can register and log in.

Each such subdomain is now a separate Laravel instance. Due to the fact that I have more and more clients, maintaining coherence between instances becomes difficult. In addition, I want to extend the application with a mobile application that needs a good api.

I am creating an API that should be able to handle multiple databases simultaneously. Each base is constructed the same way. So I would like one model or controller to be able to handle data from different databases.

The API requires authorization and this is where my problem comes from. Because I have users in different databases, I don't know how to check if the given email and password are correct.

When logging in, the application on the user's side sends an email, password and unit, which means which database to use. But how can I tell the Auth class which database to use?

My current [email protected] looks like this:

function login() {

	// In request()->input('unit') i have database name
	// Before Auth::attempt i want to say laravel to use specific db.. how to tell it him ?

	if( Auth::attempt(['email' => request()->input('email'), 'password' => request()->input('password')]) ) {
		$user = Auth::user();
		$user->generateToken();

		return response()->json(
			$user->api_token
		, 200);
	}

	return response()->json([
		"error" => "Unauthenticated."
	], 401);
}

PS. I don't use Passport or JWT - only my code

PS2. Of course all databases are included in config/database.php