tjkalinowski

tjkalinowski

Member Since 2 Years Ago

Warsaw/Siedlce Poland

DevOps at Trade Brokers Company at Poland

Experience Points 7,280
Experience Level 2

2,720 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 62
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

09 May
1 year ago

tjkalinowski left a reply on Laravel5 And Bootstrap-select

Can You show me how to inicialise it? In How to web page no info about initialisation, are you sure?

tjkalinowski left a reply on Laravel5 And Bootstrap-select

Here is Master template : /layouts/master.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">

    <title>SROKA</title>
    
    <!-- META TAGs -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="favicon.ico">

    <!-- CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
    <!-- <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.2/css/bootstrap-select.min.css">
    <!-- THEMES -->

    <!-- <link rel="stylesheet" href="https://bootswatch.com/cerulean/bootstrap.min.css"> -->
    <!-- <link rel="stylesheet" href="https://bootswatch.com/cosmo/bootstrap.min.css"> -->
    <!-- <link rel="stylesheet" href="https://bootswatch.com/cyborg/bootstrap.min.css"> -->
    <!-- <link rel="stylesheet" href="https://bootswatch.com/darkly/bootstrap.min.css"> -->
    <!-- <link rel="stylesheet" href="https://bootswatch.com/flatly/bootstrap.min.css"> -->
    <!-- <link rel="stylesheet" href="https://bootswatch.com/journal/bootstrap.min.css"> -->
    <!-- <link rel="stylesheet" href="https://bootswatch.com/lumen/bootstrap.min.css"> -->
    <!-- <link rel="stylesheet" href="https://bootswatch.com/paper/bootstrap.min.css"> -->
    <!-- <link rel="stylesheet" href="https://bootswatch.com/readable/bootstrap.min.css"> -->
    <!-- <link rel="stylesheet" href="https://bootswatch.com/sandstone/bootstrap.min.css"> -->
    <!-- <link rel="stylesheet" href="https://bootswatch.com/simplex/bootstrap.min.css"> -->
    <!-- <link rel="stylesheet" href="https://bootswatch.com/slate/bootstrap.min.css"> -->
    <!-- <link rel="stylesheet" href="https://bootswatch.com/spacelab/bootstrap.min.css"> -->
    <!-- <link rel="stylesheet" href="https://bootswatch.com/superhero/bootstrap.min.css"> -->
    <!-- <link rel="stylesheet" href="https://bootswatch.com/united/bootstrap.min.css"> -->
    <!-- <link rel="stylesheet" href="https://bootswatch.com/yeti/bootstrap.min.css"> -->

    <!-- /THEMES -->

    <!-- <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.0/css/bootstrap-datepicker.css" rel="stylesheet"> -->

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    @yield('css')
</head>

<body>

    @include('layouts.nav')

    <div class="container">
        @if(session('message'))
        <div class="alert alert-success alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
            {{@session('message')}}
        </div>
        @endif

        @yield('header')
        @yield('content')
    </div>

    <!-- Scripts -->
    <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.2/js/bootstrap-select.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.2/js/i18n/defaults-*.min.js"></script>
    <!--
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.0/js/bootstrap-datepicker.min.js"></script>
    -->
    
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <!-- <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script> -->
    
    @yield('scripts')
    <script>
        $('.date-picker').datepicker();
    </script>
</body>
</html>
08 May
1 year ago

tjkalinowski started a new conversation Laravel5 And Bootstrap-select

Hello!

I have simple question. Did you use bootstrap-select (https://silviomoreto.github.io/bootstrap-select/examples/#basic-examples)?

I did install it via Bower and add CDNJS to main template. Basic Example is not working and any other example. I do not know why?

<select class="selectpicker">
  <option>Mustard</option>
  <option>Ketchup</option>
  <option>Relish</option>
</select>

I see new element on web page, with Mustar, but when I click on drop down menu, nothing is droped down. Like HTML element is working but not animated.

tjkalinowski left a reply on L5scaffold And Pagination With Bootstrap 4.0

I did help myself. Had to alternate source code of laravel here:

/vendor/laravel/framework/src/Illuminate/Pagination/resources/views/default.blade.php

03 May
1 year ago

tjkalinowski started a new conversation L5scaffold And Pagination With Bootstrap 4.0

As you probably know pagination is not working in l5scaffold (https://github.com/alnutile/l5scaffold).

Original author use Bootstrap 3.x. I wish to use 4.x.

Can you share with community how to fix it?

In source code command is:

{!! $classname->render() !!}

At user browser above code is translated to:

                <ul class="pagination">
                    <li class="disabled"><span>&laquo;</span></li>
                    <li class="active"><span>1</span></li>
                    <li><a href="http://xxxxxx.dev/schedules?page=2">2</a></li>
                    <li><a href="http://xxxxxx.dev/schedules?page=2" rel="next">&raquo;</a></li>
            </ul>

``
01 May
1 year ago

tjkalinowski started a new conversation Front End Tempplate

Hello,

I am looking for nice and easy template (not sure the name is correct) for my Application Laravel. I am not talking about Bootstrap, it rather sets of elements. Do you know something like l5scaffold. I wanto to build application look, menus, left and right menus etc. All same look globally in my App. Do you know something like skin, or template ready to apply to project?

27 Apr
1 year ago

tjkalinowski started a new conversation Book

What do you recoment to buy? I am talking about avarage level, not beginer one.

11 Apr
2 years ago

tjkalinowski left a reply on Production Not Works = Same Code On Dev Works :)

mazwan, I DID copy production database to laptop development. And two databases are 1 to 1 identical.

I did check all tables in Events, Types and Comments table. Tables has XXX_ID fields.

For example : Comments Table has event_id Events Table has type_id Types Table has name filed.

Then command :

{{ $comment->event->type->name}}

should works.

I did inspect database content and See correct fileds, and its contents. Numbers in event_id or type_id ponts to correct data.

Relation is correctly set up.

Comments.php have
return $this->belongsTo(Event::class);

Event.php have
return $this->belongsTo(Type::class);
return $this->hasMany(Comment::class);

Type.php have
return $this->hasMany(Event::class);

Also I did some experiments in CommentController.php and found that I can acces to object $comment:

//This is experiment:

$comments = Comment::all();
$counts = Comment:all()->count();

//I can access for elements like this:

for ( $i=0; $i<$counts ; $i++) {
echo $comments->event->type->name;
}

But in View:

@foreach($comments as $comment)
 {{$comment->event->type->name}}
@endforeach

///This make error.

I think we have BUG in Laravel core.

tjkalinowski left a reply on Production Not Works = Same Code On Dev Works :)

Why the same code works on development server fine? How to explain?

10 Apr
2 years ago

tjkalinowski left a reply on Production Not Works = Same Code On Dev Works :)

I have found that this line works in CommentsController.php

echo "<BR><BR><BR>"; var_dump($comments[0]->event->type->name);

But the same not works in comments/index.blade.php

<B> {{ $comment->event->type->name}} </B>

VERY strange.....

tjkalinowski left a reply on Production Not Works = Same Code On Dev Works :)

My relations is ok.

Comment.php:

    public function Event() 
    {
        return $this->belongsTo(Event::class);
    } 

Event.php

public function Comment()
    {
        return $this->hasMany(Comment::class);
    } 

    public function type() 
    {
        return $this->belongsTo(Type::class);
    }  

Type.php

  public function event()
    {
        return $this->hasMany(Event::class);
    }        

I do not see wrong relations here. hmmm....

tjkalinowski started a new conversation Production Not Works = Same Code On Dev Works :)

Hello!

I have spend 2h searching what wrong, and found zero....

When I call URL http://production.com/comments/index I see that error.

3/3
ErrorException in 1dea0486404fc5ccd0169877e8bb3cc4003b56ab.php line 8:
Trying to get property of non-object (View: /home/aknsvip/domains/production/resources/views/comments/comment.blade.php) (View: /home/aknsvip/domains/production/resources/views/comments/comment.blade.php)

1. in 1dea0486404fc5ccd0169877e8bb3cc4003b56ab.php line 8
2. at CompilerEngine->handleViewException(object(ErrorException), 1) in PhpEngine.php line 44
3. at PhpEngine->evaluatePath('/home/aknsvip/domains/production/storage/framework/views/819ed1c26b86a6fe11ece353533e8ada68efd606.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'comments' => object(LengthAwarePaginator), 'CommentErrorCheck' => null, 'CommentError' => null)) in CompilerEngine.php line 59

Nothing new, very common error. Lets see. In 1dea0486404fc5ccd0169877e8bb3cc4003b56ab.php in line 8 I see this:

<tr>
    <td> 
        <code> 
                <?php echo e($comment->body); ?> 
        </code> 
        <br>
        <font size="-1">
                <B> <?php echo e($comment->event->type->name); ?> </B>    <-----this
                <i><?php echo e($comment->user->name); ?> -> (<?php echo e($comment->updated_at); ?>) </i>      <------this
        </font> 
    </td>
    <td>
            <?php if( Auth::user()->role == "Administrator"): ?>
                <a href="/events/<?php echo e($comment->event->id); ?>/show" class="btn btn-info btn-sm active" role="button" aria-pressed="true">Info</a>     <----this     
                <a href="/comments/<?php echo e($comment->id); ?>/destroy" class="btn btn-danger btn-sm active" role="button" aria-pressed="true">del</a>
            <?php endif; ?>
    </td>
</tr>

When I manually remove lines marekt <----this error goes off. And page loaded.

WHY???

I see that errror IS related to calling many to on relation, like in this example :

tjkalinowski left a reply on I Can See Variable But Is Not Defined, Why?

I have made it!! Thank for you help. My code looks like this:


                    @if(session()->has('results'))
                            <label for="title">Search Results:</label>                            
                            <select type="text" id="location" name="location" class="form-control" required>
                            <?php 
                                $res = Session::get('results');
                                $size = count($res);
                                for ( $i=0; $i<$size; $i++) {
                                        echo "<option value=".$res[$i]['id'].">";
                                        echo $res[$i]['name']." (".$res[$i]['code'].")";
                                        echo "</option>"; 
                                }     
                            ?>
                            </select>
                    @else
                            <label for="title">Take one:</label>
                            <select type="text" id="location" name="location" class="form-control" required>
                            @foreach($locations as $location)
                                <option value="{{$location->id}}">
                                        {{$location->name}}
                                </option>
                            @endforeach
                            </select>
                    @endif                    
                </td>

tjkalinowski started a new conversation I Can See Variable But Is Not Defined, Why?

Hello all.

I have very strange situation in my code. I am expecting to have $results as query results but the value is empty but exist and can be detected by IF. Can you point where is wrong?

Here is simple search input box, which works fine, When I type the text in input field and press Search button, it route to EventsController methode Search and returns a few records stored in $results object.

$results object is redirected back to the create.blade view but is not accessible, I put ARROW to show you where is error.

/events/create.blade.php

        <div class="form-group">
                <form method="GET" action="/events/search" />
                    {{ csrf_field() }} 
                    <input name="code" type="text" value="30" required>  
                    <button>Search</button>
                </form>
                @if(session()->has('results'))     <----this IF works
                    @foreach ( $results as $result )
                        {{$result->name}} - {{$result->code}}  <-----this code show error
                    @endforeach
                @else
                    No results.    <---- before click page is loaded and show this, correct.
                @endif
        </div>

Error code is :

Undefined variable: results (View: /Users/tomas/laravel/ekal/resources/views/events/create.blade.php)

web.php

Route::get('/events/search', '[email protected]');

EventsController.php

public function search(Request $request)
    {
        if(!empty($request->input('code'))){
            $results = Location::orderBy('name', 'asc')->where('code', 'like', '%'.$request->code.'%')->get();
            $isResults = "full";
            //dd($results);   <----- I see results
            return redirect()->back()->with('results', $results);   <----this works fine
        }        
    }

09 Apr
2 years ago

tjkalinowski started a new conversation Laravel Collective Not Works

I am learning to do input box with search button inside Create Blade page. My goal is to display result on the same page.

Question #1.

Problem is when I press Search, a URL is called (I see page reload), but action is not executed - I did put dd(somethin) to check it out, and do not see results. Even change name in EventsController to searchhhhh to see that is not executed.

Question #2. What is $variable for?

Question #3. How to return to the same page where search button is placec, and display results of search?

My code is.

/events/create.blade.php

            <div class="form-group">
                    {!! Form::open(array('method' => 'Get', 'action' => array('[email protected]', $variable))) !!}
                    {!! Form::text('search') !!}
                    <button>Search</button>
                    {!! Form::close() !!}
            </div>
web.php

Route::post('/events/search', array('as' => 'search', 'uses' => '[email protected]'));

EventsController.php

   public function search(Request $request)
    {
        dd($request->get('search'));    <---this is not executed after click on search button
    }

21 Mar
2 years ago

tjkalinowski left a reply on How To Do It In Laravel Way?

I have found whereIn!

This is example, which works:

$user = App\User::find(10) // id=10
$types = $user->types->pluck('id')->all() // array [1,6]
App\Event::whereIn('type_id', $types)->get() // works!

tjkalinowski left a reply on How To Do It In Laravel Way?

@nkho it is wrong replay. This code will not work, Event table do not have user_id. This is not display 1 and 6 type_id.

I will look at @snapey replay and think about, to understand. This is possible solution I am looking for.

20 Mar
2 years ago

tjkalinowski started a new conversation How To Do It In Laravel Way?

Hello!

How to build query in Laravel way?

We have 3 tables : [events] + [types] + [users]

[events] belongsTo [types] + [types] manyToMany [users]  or 
[users] manyTomay [types]  + [types] haveMany [events]

How to build this: SELECT * FROM TABLE events WHERE belongs to type of current user

In other words:

I want to display all events from table events, which have type_id attached to user currently logged.

I am able to check current users ID:

$currentUser = Auth::id();         // it is 10

I am able to check which types belongs to a user

$user = User::find(10);
$types = $user->types->pluck('id')->all();   // returns 1,6

I want to display all record from events which have 1 or 6 type_id.

How to build that query?

I do not want to build that, this is very bad idea. Because I do not know how many of Users has the same Type, so next query is a bad idea. I know it

$events1 = Event::where(type_id, 1)->get();
$events2 = Event::where(type_id,6)->get();

Please Help :)

19 Mar
2 years ago

tjkalinowski left a reply on Parsing Multiple HTML Imput Elements Back

Thank you willvincent

I have made my controller to solve this problem. Here is code :


public function update(Request $request, $type)
    {
        $this->validate(request(), [
            'name' => 'required'
        ]);        

        // First get normal fields and save to Type records
        $r = Type::find($type);
        $r->name = $request->name;
        $r->color = $request->color;        
        $r->save();
        
        // Remove current users
        //echo "Detach <br>";
        $olduser = $request->get('olduser');
        $oldUserCount = count($olduser);
        for ($i = 0; $i < $oldUserCount; $i++ ) {
            //echo "program ".$r->id;
            //echo " user ".$olduser[$i];
            // find a user 
            $user = User::find( $olduser[$i] );  //echo " ".$user->name;
            // Must detach
            $user->types()->detach($r->id);
            //echo "<br>";            
        }
    
        //echo "<br> attach <br>";
        // add new users to Type
        $newuser = $request->get('newuser');
        $newUserCount = count($newuser);
        for ($i = 0; $i < $newUserCount; $i++ ) {
            //echo "program ".$r->id;
            //echo " user ".$newuser[$i];
            // find a user 
            $user = User::find( $newuser[$i] );  //echo " ".$user->name;
            // Must detach to NOT duplicate
            $user->types()->detach($r->id);
            // Add user to Type
            $user->types()->attach($r->id);
            //echo "<br>";            
        }
        return redirect('/types/index');  
    }

tjkalinowski left a reply on Parsing Multiple HTML Imput Elements Back

I understand logic, but i have no knowledge how to do it.

Are you talking something about that:

<input type="checkbox" name="chk_group[]" value="value1" />Value 1<br />
<input type="checkbox" name="chk_group[]" value="value2" />Value 2<br />
<input type="checkbox" name="chk_group[]" value="value3" />Value 3<br />

The $request->get('user') must be set in update function? I will try to experiment on that, and come back later to you.

18 Mar
2 years ago

tjkalinowski started a new conversation Parsing Multiple HTML Imput Elements Back

Hello Community,

I want to ask about best parsing way in Laravel. Try to imagine that we have many input elements generated by loop like this:

                            @foreach ( $currentUsers as $currentUser)
                            <tr>                            
                                <td> <font size="-1"> {{ $currentUser->name }} </font> </td>
                                <td> <input type="checkbox" name="user" value="{{ $currentUser->id }}" checked> </input> </td>
                            </tr>                                
                            @endforeach 

And after user clikck update button it goes to TypesController.php to update function like this one :

    public function update(Request $request, $type)
    {
        $r = Type::find($type);
        $r->name = $request->name;
        $r->color = $request->color;     
         ( missing code here to store multiple inputs)   
        $r->save();
        //return redirect('/types/index');  
    }

Question : what is best way to parse multiple input fileds named olduser? For example User select 3 users names. How to parse them all. How to loop around and take each one user name, no matters how many of them are selected, one or ten.

Then how to store it in database with relation many to many, for example like this:

$user->types()->sync(1,2,6));   <----id's of user names selected by a User

or

loop from 1 to 10
{
$user->types()->attach($type->id);
}

tjkalinowski started a new conversation I Do Not Know How To Ask Google For This Problem

Hello Community,

I was searching for : how to pass varialble into anonymouse function, but failed to find solution. I know it is basic php, i am sorry for this simple question.

I do not know how to pass outside $p variable into the body of anonumouse function $q .


  public function edit(Type $type)
    {
        $p = $type->id;
        $currentUsers = Type::find($p)->users()->pluck('name');     
        $users = User::whereDoesntHave('types', function( $q ) {
            $q->where('type_id', $p);   <------here
        })->get();
        return view('types.edit', compact('type', 'currentUsers', 'users'));
    }

tjkalinowski left a reply on User Not Have Relation.

Hey vipin93, this code looks right and should works. But not working. hmmm


1/1
ErrorException in Grammar.php line 196:
Object of class Closure could not be converted to string

tjkalinowski started a new conversation User Not Have Relation.

I have Many to Many relationship : Users and Types (pivot type_user).

To find all users who have have type 1:

$users = Type::find(1)->users()->pluck('name');

To find all users who do not have any type assigned:

$users = User::doesntHave('types')->get(); 

How to find all users who have NOT type 1???

17 Mar
2 years ago
14 Mar
2 years ago

tjkalinowski left a reply on How To Build This Eloquent Query?

Joke?

FatalThrowableError in TypesController.php line 85: Call to undefined function App\Http\Controllers\doesntHave()

tjkalinowski started a new conversation How To Build This Eloquent Query?

How to select all users in table "users", which ID is not listed in pivot table "type_user" in column "user_id"

In other words, I have tables : users, types, and pivot type_user. And want to select all users which are not attached to any type. They are not listed in pivot table.

Tables are standard names : users, types, and type_user.

I am able to select all users assigned to particular type id by this:

$currentUsers = Type::find(1)->users()->pluck('name');  --->return 2 records

I am able to select all users too:

$users = User::all(); -----> return 6 records

In other words how to display all users $user minus $currentUsers (6-2 = 4 users) by eloquent command set. In this example 4 users are not attached to pivot table. I am talking about this:

>>> $user->types()->attach(1)
07 Mar
2 years ago

tjkalinowski left a reply on Many To Many Relationship

Thank you, this works and display all information I wanted. But now, another problem, how to display it over blade?

Should I return $users to Blade like this:

return view('types.index', compact ('users));

And then re-code the sample of code to index.blade.php :

@foreach ( $users as $user )
    @foreach ( $user->types as $type)
         {{$type->name}}
  @endofeach
@endforeach 

tjkalinowski started a new conversation Call To Undefined Method Illuminate\Database\Query\Builder::type()

I have Types and Users tables like this:

Schema::create('type_user', function (Blueprint $table) {
            $table->integer('type_id');
            $table->integer('user_id');
            $table->primary(['type_id', 'user_id']);
            $table->timestamps();
        });


   public function users()
    {
      return $this->belongsToMany(User::class)->withTimestamps();
    }  


    public function types()
    {
      return $this->belongsToMany(Type::class, 'types')->withTimestamps();
    }  

In Tinker:

>>> $user = User::find(10);
>>> $type = Type::find(1);
>>> $user->type()->attach($type->id);
BadMethodCallException with message 'Call to undefined method Illuminate\Database\Query\Builder::type()'
>>> $user->type()->attach(1);
BadMethodCallException with message 'Call to undefined method Illuminate\Database\Query\Builder::type()'
>>> 

What to do?

tjkalinowski left a reply on Many To Many Relationship

Your code not working.

     $user = User::all();
        foreach ($user->types as $type) {
            echo $type->name;
        }        

Exception in Collection.php line 1479: Property [types] does not exist on this collection instance.

tjkalinowski started a new conversation Many To Many Relationship

Lets assume, that we have Users and Types, and pivot type_user tables ready. We have done models User and Type relationship.

  • How to display all records in Types table one by one, and its Users assigned?
  • How to display all records in Types tables, which is of type 1 or type 2
  • Can you give me good source of example codes?

Users id name 1 Name1 2 Name2

Types id name 1 Type1 2 Type2

type_user id name_id type_id 1 1 1 2 1 2 3 2 1 4 2 2

How to display example screen : Name 1 has Type1 and Type2 Name 2 has Type1 and Type2

02 Mar
2 years ago

tjkalinowski left a reply on Sort And Paginate

Tanks a lot!

How to find out what is URL link for each pages to build Navigation like this:

| < | 1 | 2 | 3 | 4 | ... | 15 | > |

I know :

$results->nextPageUrl()
$results->previousPageUrl()
$results->lastPage()

Do I need to make a loop, and count from 1 to lastPage() do display individual numbers? I any automate way?

tjkalinowski left a reply on Sort And Paginate

Due to this documentation link : https://laravel.com/docs/5.1/pagination#displaying-results-in-a-view

You may add to the query string of pagination links using the appends method. For example, to append &sort=votes to each pagination link, you should make the following call to appends

{!! $users->appends(['sort' => 'votes'])->render() !!}

How to sort ASC or DESC?

tjkalinowski started a new conversation Sort And Paginate

I can sort events:

$events = Event::all()->sortByDesc('date');

I cant paginate too:

$events = Event::where('id', '>', 0)->paginate(7);

How to do both?

$events = Event::where('id', '>', 0)->sortByDesc('date')->paginate(7);

BadMethodCallException in Builder.php line 2508: Call to undefined method Illuminate\Database\Query\Builder::sortByDesc()

16 Feb
2 years ago

tjkalinowski left a reply on Change Public Folder

Thank you all for replay, but my question was not precise. I was asking about change the patch in Laravel App files.

I am not talking about changing server HTTP apache or Nginx settings itself. Try to imagine that i have virtual hosting service with hardcoded path name, and my goal is to just laravel to feet into servers path.

For example, my path is /home/domains/public_html and i want to upload my laravel app to /home/domains and the rename public folder to public_html and change laravel config to SEE it. In default setting it always SEE APP_folder/public.

Keeping that in mind, can you tell me again?

I have found in config/filesystems.php file that:


'root' => storage_path('app/public')

15 Feb
2 years ago

tjkalinowski started a new conversation Change Public Folder

How to change Laravel public folder to any other name. For example "public_html" ? How to relocate the public folder to different path?

tjkalinowski left a reply on Help Me Understand How To Deploy My App For Production - Config Problem

Hello fabricecw!

Thanks for replay. I do not have rights to define Document Root Directory for Apache HTTP server. My server path is /domains/mydomain.com/public_html/ekal and this is my document root and I cant change that. My URL is http://ekal.mydomain.com/.

By keep it in mind, can you help me to solve problem? If login page works, the any other page have too.

tjkalinowski left a reply on Help Me Understand How To Deploy My App For Production - Config Problem

This may be good for help:

URL: http://ekal.mydomain/events/index ERROR: 404

My web.php

Route::get('/events/index', '[email protected]');

tjkalinowski started a new conversation Help Me Understand How To Deploy My App For Production - Config Problem

Hello All,

I am new to Laravel and this is my first post. I have problem with deployment my app to hosting. I have Forbidden error or Not Found due to path problems.

Here is my steps how I did it:

  1. My Laravel app is working on Valet development environment on MacOS well at /Users/tomas/laravel/ekal and is available at http://ekal.dev locally. Database is mySQL at localhost.

  2. I did login to DirectAdmin v1.50.1 my hosting and created virtual domain "ekal.mydomain.com" located on server at path : /domains/mydomain.com/public_html/ekal/

  3. Compress local ekal app directory to ekal.zip file and FTP it to hosting under server path /domains/mydomain.com/public_html/ekal/ekal.zip

  4. I uncompress ZIP file to the same path.

  5. I did edit /domains/mydomain.com/public_html/ekal/.env file and change database setting to right one.

APP_URL=http://ekal.mydomain.com
DB_CONNECTION=mysql
DB_HOST=mydomain.com
DB_PORT=3306
DB_DATABASE=ekal
DB_USERNAME=ekal
DB_PASSWORD=secret
  1. I did export my database from local server to SQL file, and upload this to my hosting via PHPmyAdmin as database ekal.

  2. I edit file /domains/mydomain.com/public_html/ekal/config/app.php and change:

    'url' => env('APP_URL', 'http://ekal.mydomain.com'),

7. I change permissions to 777 for /domains/mydomain.com/public_html/ekal/storage/framework



That all.


When I open web browse and type URL ekal.mydomain.com i see Forbidden error 403.

When I open ekal.mydomain.com/public I see my APP first page. But when i click on any link like "/users/index" app try to load URL : ekal.mydomain.com/users/index.php and can't find it with error Not Found 404.

I have notice that, CSS files are not loaded. So i did move from 

/domains/mydomain.com/public_html/ekal/public/css 

to one level up to path 

/domains/mydomain.com/public_html/ekal/css 

and see that APP can now find the file app.css and web page have CSS elements in DOM.

This help me to load CSS files, but do not solve problem with others.




I did search for solution, and found that proper way for deploy app is to upload all files on level up over public_html directory. Like this:

cd /domains/mydomain.com/public_html/ekal
cd /domains/mydomain.com/public_html    <--------upload here
UPLOAD app files here
DELETE ekal
MOVE public -> ekal

But in my case i can't do that. 
I can't upload files to upper level. 
/domains/mydomain.com/public_html/ekal is root URL for ekal.mydomain.com
/domains/mydomain.com/public_html is root URL for whole virtual server, i can't modify it.

I can't edit apache.config files. 
I have only FTP access to hosting and DirectAdmin web admin.



My question is how to modify configuration of laravel APP itself to works?