Bosstone

Bosstone

Member Since 1 Year Ago

Experience Points 770
Experience Level 1

4,230 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 0
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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.

01 Jul
1 month ago

Bosstone left a reply on SQLSTATE[HY000]: General Error: 1215 Cannot Add Foreign Key

@BOBBYBOUWMANN - Hi BobbyBouwmann, thank you very much. Works like a charm :-)

Can you also tell me, why I get the following error message when I try to refresh the migrate:

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'tasks' already exists (SQL: create table tasks (id int unsigned not null auto_increment primary key, user_id bigint unsigned null, title varchar(255) not null, is_complete tinyint(1) not null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

I have set up the table tasks to drop if already exists:

<?php
 use Illuminate\Support\Facades\Schema;
 use Illuminate\Database\Schema\Blueprint;
 use Illuminate\Database\Migrations\Migration;
 class CreateTasksTable extends Migration
{
/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('tasks', function (Blueprint $table) {
        $table->increments('id');
        $table->unsignedBigInteger('user_id')->nullable();
        $table->string('title');
        $table->boolean('is_complete');
        $table->timestamps();
        $table->foreign('user_id')->references('id')->on('users');
    });
}
/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::dropIfExists('tasks');
}

}

Thank you for your time!

Best Regards, Stefan

Bosstone started a new conversation SQLSTATE[HY000]: General Error: 1215 Cannot Add Foreign Key

Hi, I am unable to migrate my tables as I cannot add foreign key "SQL: alter table tasks add constraint tasks_user_id_foreign foreign key (user_id) references users (id))"

I am setting up a table "tasks" using the following code:

 public function up()
{
    Schema::create('tasks', function (Blueprint $table) {
        $table->increments('id');
        $table->unsignedInteger('user_id')->nullable();
        $table->string('title');
        $table->boolean('is_complete');
        $table->timestamps();
        $table
            ->foreign('user_id')
            ->references('id')
            ->on('users');
    });
}

Name of the Migrations of user:

database/migrations/2014_1012000000_create_users_table.php

Name of the Migrations of tasks:

database/migrations/2020_06_27_052141_create_tasks_table.php

So, the table users will be created first and then in the end tasks. But unfortunately the migration is not working...

Please see the screenshot: https://www.dropbox.com/s/nzaodlqu4ksxv0q/Screenshot%202019-07-01%20at%2021.34.48.png?dl=0

Thanks for any suggestions and advices!

Best Regards, Stefan

27 Jun
1 month ago
26 Jun
1 month ago

Bosstone started a new conversation SQLSTATE[HY000]: General Error: 1364 Field "adresse" Doesn't Have A Default Value

Hi, I have extended the table user with fields: adresse, rolle, vorname, plz, ort, telefon. When registering a user, I just want to know vorname (first name), name, email, password and rolle.

I do not know, why adresse will be asked, as I never pass it during first registration?

User.php looks like this:

namespace App;

use Illuminate\Notifications\Notifiable; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable { use Notifiable;

/**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $fillable = [
    'name', 'email', 'password', 'vorname','rolle',
];

/**
 * The attributes that should be hidden for arrays.
 *
 * @var array
 */
protected $hidden = [
    'password', 'remember_token',
];

/**
 * The attributes that should be cast to native types.
 *
 * @var array
 */
protected $casts = [
    'email_verified_at' => 'datetime',
];

}

RegisterController looks like this:

namespace App\Http\Controllers\Auth;

use App\User; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; use Illuminate\Foundation\Auth\RegistersUsers;

class RegisterController extends Controller { /* |-------------------------------------------------------------------------- | Register Controller |-------------------------------------------------------------------------- | | This controller handles the registration of new users as well as their | validation and creation. By default this controller uses a trait to | provide this functionality without requiring any additional code. | */

use RegistersUsers;

/**
 * Where to redirect users after registration.
 *
 * @var string
 */
protected $redirectTo = '/home';

/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
    $this->middleware('guest');
}

/**
 * Get a validator for an incoming registration request.
 *
 * @param  array  $data
 * @return \Illuminate\Contracts\Validation\Validator
 */
protected function validator(array $data)
{
    return Validator::make($data, [
        'name' => ['required', 'string', 'max:255'],
        'vorname' => ['required', 'string', 'max:255'],
        'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
        'password' => ['required', 'string', 'min:8', 'confirmed'],
        'rolle' => ['required', 'string'],
    ]);
}

/**
 * Create a new user instance after a valid registration.
 *
 * @param  array  $data
 * @return \App\User
 */
protected function create(array $data)
{
    return User::create([
        'name' => $data['name'],
        'vorname' => $data['vorname'],
        'email' => $data['email'],
        'password' => Hash::make($data['password']),
        'rolle' => $data['rolle'],
    ]);
}

}

register.blade looks like this:

@extends('layouts.app')

@section('content')

{{ __('Register') }}
            <div class="card-body">
                <form method="POST" action="{{ route('register') }}">
                    @csrf

                    <div class="form-group row"  data-toggle="buttons">
                        <label for="rolle" class="col-md-4 col-form-label text-md-right">{{ __('Rolle') }}</label>

                        <div class="col-md-6">
                          <div class="btn-group btn-group-toggle" data-toggle="buttons">
                                <label class="btn btn-secondary active">
                                  <input type="radio" name="rolle" value="0" id="0" autocomplete="off" checked> Personal
                                </label>
                                <label class="btn btn-secondary">
                                  <input type="radio" name="rolle" value="1" id="1" autocomplete="off"> Company
                                </label>
                            @error('typ')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>
                  </div>

                  <div class="form-group row">
                      <label for="vorname" class="col-md-4 col-form-label text-md-right">{{ __('Vorname') }}</label>

                      <div class="col-md-6">
                          <input id="vorname" type="text" class="form-control @error('vorname') is-invalid @enderror" name="vorname" value="{{ old('vorname') }}" required autocomplete="vorname" autofocus>

                          @error('vorname')
                              <span class="invalid-feedback" role="alert">
                                  <strong>{{ $message }}</strong>
                              </span>
                          @enderror
                      </div>
                  </div>

                    <div class="form-group row">
                        <label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>

                        <div class="col-md-6">
                            <input id="name" type="text" class="form-control @error('name') is-invalid @enderror" name="name" value="{{ old('name') }}" required autocomplete="name">

                            @error('name')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>

                    <div class="form-group row">
                        <label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>

                        <div class="col-md-6">
                            <input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email') }}" required autocomplete="email">

                            @error('email')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>

                    <div class="form-group row">
                        <label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>

                        <div class="col-md-6">
                            <input id="password" type="password" class="form-control @error('password') is-invalid @enderror" name="password" required autocomplete="new-password">

                            @error('password')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>

                    <div class="form-group row">
                        <label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>

                        <div class="col-md-6">
                            <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required autocomplete="new-password">
                        </div>
                    </div>

                    <div class="form-group row mb-0">
                        <div class="col-md-6 offset-md-4">
                            <button type="submit" class="btn btn-primary">
                                {{ __('Register') }}
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection
05 Nov
9 months ago

Bosstone left a reply on Get Data From Two Tables

Dear Snapey, dear Arthvrian,

thanks a lot for your help. I do not get it :-(

in my Project.php I have

public function user()
{
    return $this->belongsTo(\App\User::class, 'user_id');
}

in my User.php I have

public function projects()
  {
      return $this->hasMany(\App\Project::class, 'user_id');
  }

When I use

$results = User::with('projects')->get();

in my controller, then I get all data from User, but no data from projects.

@foreach($results as $project)
     <br>
        <tr>
            <td>{{ $project->name }}</td>
            <td>{{ $project->user_id }}</td>
            <td>{{ $project->cat_name }}</td>
         </tr>
 @endforeach

The first Data is from User, the other two from Project and those Variables will not be shown.

Thank you for your Time and support.

Stefan

Bosstone started a new conversation Get Data From Two Tables

Hi, how can I get all the data from two tables:

users, projects

My tables are connected with user.id & projects.user_id

This is my Controller:

public function adminProjectShowAll() {
    
    $user = Auth::user();
    $stat = 1;
    $projects = Project::where('stat' <> $stat );

    
  return view('admin-project-show-all', compact('projects', 'user'));
    
}

my sql code would be: select * from users, projects where user.id = projects.user_id

This is my View:

@foreach($projects as $project)
                  <br>
                  <tr>
                    <td>{{ $project->name }}</td>
                    <td>{{ $project->user_id }}</td>
                    <td>{{ $project->cat_name }}</td>
                  </tr>
                  @endforeach 

Error: No Error, but nothing will be displayed...

Thank you for your help and support!

Best Regards,

Stefan

07 Oct
10 months ago

Bosstone left a reply on E-Mail Sending

Thank you very much for your answer. Works like a charm :-)

Where can I edit the texts in the E-Mail which Laravel sends?

Stefan

Bosstone started a new conversation E-Mail Sending

Hi Folks,

I have a problem sending E-Mail. I get an error message when I use the "lost password function":

my .env File (with Placeholders):

MAIL_DRIVER=smtp
MAIL_HOST="server1.weddingcompany.eu"
MAIL_PORT=587
MAIL_USERNAME="[email protected]"
MAIL_PASSWORD="*******"
MAIL_ENCRYPTION=tls

the mail.php File looks like this:


return [

    /*
    |--------------------------------------------------------------------------
    | Mail Driver
    |--------------------------------------------------------------------------
    |
    | Laravel supports both SMTP and PHP's "mail" function as drivers for the
    | sending of e-mail. You may specify which one you're using throughout
    | your application here. By default, Laravel is setup for SMTP mail.
    |
    | Supported: "smtp", "sendmail", "mailgun", "mandrill", "ses",
    |            "sparkpost", "log", "array"
    |
    */

    'driver' => env('MAIL_DRIVER', 'smtp'),

    /*
    |--------------------------------------------------------------------------
    | SMTP Host Address
    |--------------------------------------------------------------------------
    |
    | Here you may provide the host address of the SMTP server used by your
    | applications. A default option is provided that is compatible with
    | the Mailgun mail service which will provide reliable deliveries.
    |
    */

    'host' => env('MAIL_HOST', 'server1.weddingcompany.eu'),

    /*
    |--------------------------------------------------------------------------
    | SMTP Host Port
    |--------------------------------------------------------------------------
    |
    | This is the SMTP port used by your application to deliver e-mails to
    | users of the application. Like the host we have set this value to
    | stay compatible with the Mailgun e-mail application by default.
    |
    */

    'port' => env('MAIL_PORT', 587),

    /*
    |--------------------------------------------------------------------------
    | Global "From" Address
    |--------------------------------------------------------------------------
    |
    | You may wish for all e-mails sent by your application to be sent from
    | the same address. Here, you may specify a name and address that is
    | used globally for all e-mails that are sent by your application.
    |
    */

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],

    /*
    |--------------------------------------------------------------------------
    | E-Mail Encryption Protocol
    |--------------------------------------------------------------------------
    |
    | Here you may specify the encryption protocol that should be used when
    | the application send e-mail messages. A sensible default using the
    | transport layer security protocol should provide great security.
    |
    */

    'encryption' => env('MAIL_ENCRYPTION', 'tls'),

    /*
    |--------------------------------------------------------------------------
    | SMTP Server Username
    |--------------------------------------------------------------------------
    |
    | If your SMTP server requires a username for authentication, you should
    | set it here. This will get used to authenticate with your server on
    | connection. You may also set the "password" value below this one.
    |
    */

    'username' => env('MAIL_USERNAME'),

    'password' => env('MAIL_PASSWORD'),

    /*
    |--------------------------------------------------------------------------
    | Sendmail System Path
    |--------------------------------------------------------------------------
    |
    | When using the "sendmail" driver to send e-mails, we will need to know
    | the path to where Sendmail lives on this server. A default path has
    | been provided here, which will work well on most of your systems.
    |
    */

    'sendmail' => '/usr/sbin/sendmail -bs',

    /*
    |--------------------------------------------------------------------------
    | Markdown Mail Settings
    |--------------------------------------------------------------------------
    |
    | If you are using Markdown based email rendering, you may configure your
    | theme and component paths here, allowing you to customize the design
    | of the emails. Or, you may simply stick with the Laravel defaults!
    |
    */

    'markdown' => [
        'theme' => 'default',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],

];

I get Error Message when I try to use the lost password function:

stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

What can I do?

Best Regards, Stefan

02 Jul
1 year ago

Bosstone started a new conversation Infinite Scroll - JScroll

Hi Folks,

I am trying to lazy load data from Mysql - To test, I have put 8000 entries into the database.

I have added <div class = "infinite scroll" to my HTML Source:

<div class="infinite-scroll">
                      @foreach($projects as $project)
                          <p style=""><b>Kategorie: {{ $project->cat_name }}
                          <p style=""><b>Projektname:  {{ $project->projektname }} ID: {{ $project->id }}</b></p>
                          @if ( $project->stat === 0 )
                            <p style=""><b>Projektstatus: eingereicht</b></p>
                          @elseif ( $project->stat === 2 )
                            <p style=""><b>Projektstatus: freigegeben</b></p>
                          @elseif ($project->stat === 3 )
                            <p style=""><b>Projektstatus: zur├╝ckgewiesen</b></p>
                          @endif

                          <div class="form-group">
                              <label for="comment">Projektinfos:</label>
                              <textarea class="form-control" rows="5" id="comment">Projektname: {{$project->name}} \n Projectbeschreibung: {{$project->beschreibung }}</textarea>
                          </div>
                          <br>
                          <div class="row">
                            <?php $imageCount = 0;?>
                          @foreach($project->images as $image)

                            <?php $imageCount ++; ?>

                              <div class="column" id = "thumb-<?php echo md5($image->filename)?>">
                                <img src="{{ $image->thumb_url }}" alt="{{$image->filename}}" style="width:100%;height:100%" onclick="openModal('{{$project->name}}');currentSlide(<?php echo $imageCount ?> , '<?php echo $project->name?>')" class="hover-shadow cursor">
                              </div>

                          @endforeach

                          </div>
                          <br>


                          <form method="POST" action="{{ route('project-rated') }}">
                              @csrf
                                {{ Form::hidden('project_id', $project->id) }}
                                <label for="Cat"></label>
                                    <select class="form-control" name="counts" id="counts" data-parsley-required="true" onchange='this.form.submit()'>
                                      <option value="10">10</option>
                                      <option value="20">20</option>
                                      <option value="30">30</option>
                                      <option value="40">40</option>
                                      <option value="50">50</option>
                                      <option value="60">60</option>
                                      <option value="70">70</option>
                                      <option value="80">80</option>
                                      <option value="90">90</option>
                                      <option value="100">100</option>
                                    </select>
                              </form>

                      <div id="myModal-{{$project->name}}" class="modal">
                        <span class="close cursor" onclick="closeModal('{{$project->name}}')">&times;</span>
                        <div class="modal-content">
                          <div class = "wide_wrapper" >
                            @foreach($project->images as $image)
                            <div class="mySlides-<?php echo $project->name ?>" data-responsive="true" style = "width : 100%;height : 100%;" id = "wide-<?php echo md5($image->filename)?>">
                              <img src="{{ $image->url }}" alt="Nature and sunrise" style="width: 100%; ">
                            </div>
                            @endforeach

                          </div>
                          <a class="prev" onclick="plusSlides(-1 , '<?php echo $project->name?>')">&#10094;</a>
                          <a class="next" onclick="plusSlides(1 , '<?php echo $project->name?>')">&#10095;</a>

                          <div style = "height : 30px;background : black">
                          </div>

                          <div class = "clearfix">
                            <?php $imageCount = 0;?>
                            @foreach($project->images as $image)
                            <?php $imageCount ++; ?>
                            @if ($user->rolle === 0)
                            <div class="column clearfix" id = "slide-<?php echo md5($image->filename)?>">
                              <div class = "clearfix text-center" style = "background : grey">
                                <span class="glyphicon glyphicon-trash" onclick="del('{{$image->filename}}' , '<?php echo md5($image->filename)?>')"></span>
                              </div>
                              <div class = "image-wrapper">
                                  <img id = "slideimg-<?php echo md5($image->filename)?>" class="demo-<?php echo $project->name ?> cursor" src="{{ $image->thumb_url }}" style="width:100%" onclick="currentSlide(<?php echo $imageCount ?> , '<?php echo $project->name?>')" alt="Nature and sunrise">
                              </div>
                            </div>
                            @endif
                            @endforeach

                        </div>

                        </div>
                        <div style = "height : 80px"></div>
                      </div>
                      <div style="height: 50px;"></div>
                      @endforeach
                    </div>

Here is the Javascript:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="/js/jquery.jscroll.min.js"></script>

<script type="text/javascript">
        $(function() {
            $('.infinite-scroll').jscroll({
                autoTrigger: true,
                loadingHtml: '<img class="center-block" src="{{ asset('images/loading.gif') }}" alt="Loading..." />',
                padding: 0,
                nextSelector: '.pagination li.active + li a',
                contentSelector: 'div.infinite-scroll',
                callback: function() {
                    $('ul.pagination').remove();
                }
            });
        });
</script>

The Script is from that site: https://laraget.com/blog/implementing-infinite-scroll-pagination-using-laravel-and-jscroll

The Data will be loaded, but not lazy (and therefore super slow), and the gif will never be shown...

Can anyone help me out? What am I missing? Thanks for any hints and suggestions.

Bosstone left a reply on Form Validation: Textarea - Maxlength

If someone needs the solution:

The Javascript - Code - I take the variable {{ $cats->words }} from the database.

<script src="http://code.jquery.com/jquery-1.5.js"></script>
    <script>
        var max = {{ $cats->words }};
        $(document).ready(function() {
          $("#beschreibung").on('keyup', function() {
      var words = this.value.match(/\S+/g).length;

      if (words > max) {
        // Split the string on first 200 words and rejoin on spaces
        var trimmed = $(this).val().split(/\s+/, max).join(" ");
        // Add a space at the end to make sure more typing creates new words
        $(this).val(trimmed + " ");
      }
      else {
        $('#display_count').text(words);
        $('#word_left').text(max-words);
      }
    });
  });

The HTML Code:

<div class="form-group row">
        <label for="beschreibung" class="col-md-4 col-form-label text-md-right">{{ __('Beschreibung*') }}</label>

        <div class="col-md-6">

            <textarea id="beschreibung" rows="10" class="form-control{{ $errors->has('beschreibung') ? ' is-invalid' : '' }}" name="beschreibung" value="{{ old('beschreibung') }}" required></textarea>
            Allowed Words: {{ $cats->words }} - Total Words : <span id="display_count">0</span> Words!
            @if ($errors->has('beschreibung'))
                <span class="invalid-feedback">
                    <strong>{{ $errors->first('beschreibung') }}</strong>
                </span>
            @endif
        </div>
    </div>

Bosstone left a reply on Form Validation: Textarea - Maxlength

Dear BishoyWaghi - thanks for your suggestion :-)

Bosstone started a new conversation Form Validation: Textarea - Maxlength

Hi Folks,

how can I count the number of words inside a textarea? I have a variable ($cats->count) where the number of allowed words are defined.

<div class="col-md-6">
          <div id="charNum">
            <textarea id="desc" class="form-control{{ $errors->has('desc') ? ' is-invalid' : '' }}" name="desc" value="{{ old('desc') }}" required></textarea>

            @if ($errors->has('desc'))
                <span class="invalid-feedback">
                    <strong>{{ $errors->first('desc') }}</strong>
                </span>
            @endif
          </div>
        </div>

Thank you for any suggestions

Kind Regards,

Stefan

22 Jun
1 year ago

Bosstone left a reply on Show Everything From 3 Tables Where Not In 1 Table

@burlresearch Thank you very much! Exactly what I have achieved! Kind Regards, Stefan!

21 Jun
1 year ago

Bosstone started a new conversation Show Everything From 3 Tables Where Not In 1 Table

Hi Folks,

sorry for that silly title. I try to explain what I want to achieve:

I am reprogramming a Voting Website. The user is uploading Projects, the judge is voting on them. As there are several judges, I have a "help table: Table Count" where - after a judge has voted on a project - his user_id and the project_id will be saved.

I have 4 tables

Table = User (with id)
Table = Project (with id and user_id) (the Project Table is connected via user_id to Table User)
Table = Image (with id, project_id) (there are the images stored - connected via project_id to Project)
Table = Count (with id, project_id, user_id) (this is the helper Table - connected to Project and User via project_id and user_id)

Class Count

class Count extends Model
{
  public function project()
    {
        return $this->belongsTo(\App\Project::class, 'project_id');
    }

    public function user()
      {
          return $this->belongsTo(\App\User::class, 'user_id');
      }
}

Class Project:

public function images()
    {
        return $this->hasMany(\App\Image::class, 'project_id');
    }

    public function user()
    {
        return $this->belongsTo(\App\User::class, 'user_id');
    }

    public function cat()
      {
          return $this->belongsTo(\App\Cat::class, 'cat_id');
      }

Class Image:

public function project()
    {
        return $this->belongsTo(\App\Project::class, 'project_id');
    }

Class User:

public function projects()
      {
          return $this->hasMany(\App\Project::class, 'user_id');
      }

I know, I can show all the projects (with the connected images) like this (in this case, all projects with stat = 2 will be shown):

$projects = Project::with(['images' => function($query){
        $query->where('state' , 0 );
      }])
      ->where('stat', '=', '2')
      ->whereHas('user', function ($query) use ($user) {
                        $query->where('id', '=', $user->id);

                    })->get();

What I want to achieve in the end is as follows:

I want to show all the projects (and connected images) from Table: Project where the combination of user_id and project_id is not in table Count

Can anyone advice me how to solve this issue?

Kind Regards,

Stefan

Bosstone left a reply on Fetch Data From Two Tables

Solved id:

$projects = Project::with(['images' => function($query){
        $query->where('state' , 0 );
      }])
      ->where('stat', '!=', '1')
      ->whereHas('user', function ($query) use ($user) {
                        $query->where('id', '=', $user->id);

                    })->get();

:-)

Bosstone started a new conversation Fetch Data From Two Tables

Hi Folks,

I have 2 Tables (projects and images) which I can fetch like this:

$projects = Project::with(['images' => function($query){
        $query->where('state' , 0 );
      }])->whereHas('user', function ($query) use ($user) {
                        $query->where('id', '=', $user->id);

                    })->get();

The Project Table has a field "stat" where the stat of the project is defined:

0 = uploaded by user 1 = deleted by user 2 = verified by admin 3 = rejected.

The Image Table has a field "state" where 0 = ok, 1 = deleted

Currently I am fetching all the projects with images with state 0 from the logged in user. What can I do to fetch only the projects with stat = 0 || stat = 2 || stat = 3?

Thank you for your advice!

Stefan

19 Jun
1 year ago

Bosstone left a reply on Textarea: Show Different Variables

Dear Snapey thanks for the hint with the Backticks ;-) I want to display more variables into one textarea and I need a linebreak after each variable.

I tried with

\n
</br>

The option

{!! nl2br(e($text))!!}

will not work, as I try to display several variables - or am I wrong?

Kind Regards,

Stefan

Bosstone started a new conversation Bootstrap Dropdown With Value

Hi Folks,

in my App I have a function where the judges can rate projects. Using this code

<div class="col-md-6">
                         <select class="form-control" name="vote" id="vote">
                           <option value="10">10</option>
                           <option value="20">20</option>
                           <option value="30">30</option>
                           <option value="40">40</option>
                           <option value="50">50</option>
                           <option value="60">60</option>
                           <option value="70">70</option>
                           <option value="80">80</option>
                           <option value="90">90</option>
                           <option value="100">100</option>
                         </select>
                     </div>
                     <button type="submit" class="btn btn-primary" value = "vote" name="submit">
                         {{ __('Rate') }}
                     </button>
                     @endif 
</form>

I have a dropdown and a button. As this solution works, but looks ugly, I learned, that there is a CSS in Bootstrap for a dropdown, but I cannot send values with that:

<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Dropdown Example
<span class="caret"></span></button>
<ul class="dropdown-menu">
  <li><a href="#">HTML</a></li>
  <li><a href="#">CSS</a></li>
  <li><a href="#">JavaScript</a></li>
   </ul>
 </div>
</div>

Is there a solution for sending values in the second dropdown?

Thanks for any advice!

Stefan

Bosstone started a new conversation Textarea: Show Different Variables

Hi Folks,

I want to display several Variables inside a Textarea:

<textarea class="form-control" id="projects"> Projectname: {{$project->name}
<br>ProjectDescription: {{$project->desc }}</textarea>

When I use the code above, then will be printed, and ProjectDescription ist in the same line...

Thank you for your advice!

Kind Regards,

Stefan

Bosstone started a new conversation Bootstrap Container Width - Make Container "wider"

Hi Folks,

how can I make a Bootstrap container "wider"? I have seen in app.css that there is

{.container{max-width:540px}}

But when I change it to 900 the container is still the same wide, but oriented left instead of center...

Thank you for any help!

Kind Regards,

Stefan

11 Jun
1 year ago

Bosstone left a reply on Intervention: Image Manipulation On The Fly?

Dear Snapy, thank you very much for your support. Works like a charm :-)

Kind Regards,

Stefan

10 Jun
1 year ago

Bosstone left a reply on Intervention: Image Manipulation On The Fly?

Dear Snapy thank you for your feedback. I have made it as you suggested, but I am not able to use aspect ratio:

I am saving the thumbnails like

$img = Image::make($thumbnailpath)->resize(250, 150)->save($thumbnailpath);

Intervention Image tells that I have to use:

$img->resize(null, 200, function ($constraint) { $constraint->aspectRatio(); });

but when I adapt my code, then I get a "unexpected } error"

$img = Image::make($thumbnailpath)->resize(null, 200, function ($constraint) { $constraint->aspectRatio()})->save($thumbnailpath);

How can I solve this issue? I want all the images with a width of 200 and an aspected Ratio...

Kind Regards,

Stefan

31 May
1 year ago

Bosstone started a new conversation Intervention: Image Manipulation On The Fly?

Hi Folks,

I have 2 Tables (Images: Name, URL, Project_ID - Projects: Name, User_ID). I use eloquent to fetch the Data:

Controller:

public function ProjectShow () {

  $user = Auth::user();


  $projects = Project::with('images')
                ->whereHas('user', function ($query) use ($user) {
                    $query->where('id', '=', $user->id);
                })->get();

return view('project-show', compact('projects', 'user'));

}

Blade:

@foreach($projects as $project)

This is Project Name: {{ $project->name }}

@foreach($project->images as $image)
    <p>This is Project FotoURL:  <img src ="{{ $image->url }}" alt=""></p>
@endforeach

@endforeach

To show thumbnails, I have installed Intervention Package with:

php composer.phar require intervention/image

and entered the required data in config/app (providers, aliases)

I have watched the Thumbnail Video, but I am stuck as in the Video I have to add a ->thumbnail_ extension to the variable, but as I am using $projects->url I am not able to add this "extra" ->thumbnail_ stuff.

How can I solve this to show thumbnails (5 in a row, max 3 lines? Can I do this on the fly in the blade, or do I have to manipulate the image in the controller?

Sorry if already asked, but I was not able to find a solution for this request...

Kind Regards

Stefan

Bosstone left a reply on Fetch Data In Blade From Eloquent?

Dear Tykus & himanshu-dhiman

thank you very much for your feedback. I am very impressed how fast you were and what I am missing...

Kind Regards,

Stefan

Bosstone started a new conversation Fetch Data In Blade From Eloquent?

Hi Folks,

I am new to laravel and I am stuck at this problem:

I have 3 tables:

User: id, name Projects: id, name, user_id Images: id, name, project_id

Using Eloquent I can fetch any projects connected to a user and the images connecting to the project:

public function ProjectShow () {

  $user = Auth::user();

  $projects = Project::with('images')
                ->whereHas('user', function ($query) use ($user) {
                    $query->where('id', '=', $user->id);
                })->get();

 return view('project-show', get_defined_vars())->with(['user' => $user]);

}

When I "return $projects;" then I will get this result:

{"id":73,"user_id":1,"name":"dfds","projektname":"1527685835","cat_id":1,"beschreibung":null,"youtube":null,"copyright":null,"testimonial":null,"check":0,"ort":null,"stat":0,"created_at":null,"updated_at":null,"deleted_at":null,"images":[{"id":4,"project_id":73,"filename":"15276858427.png","url":"/Users/sl/Developer/awa/public/images/1/1/15276858427.png","filesize":null,"created_at":"2018-05-30 13:10:42","updated_at":"2018-05-30 13:10:42","deleted_at":null},{"id":5,"project_id":73,"filename":"15276858428.png","url":"/Users/sl/Developer/awa/public/images/1/1/15276858428.png","filesize":null,"created_at":"2018-05-30 13:10:42","updated_at":"2018-05-30 13:10:42","deleted_at":null},{"id":6,"project_id":73,"filename":"152768584224Alle.png","url":"/Users/sl/Developer/awa/public/images/1/1/152768584224Alle.png","filesize":null,"created_at":"2018-05-30 13:10:42","updated_at":"2018-05-30 13:10:42","deleted_at":null},

Where id:73 is the ID from projects and id:4 is the connected Images ID

When I remove the "return $projects;" then I am not able to fetch the $projects Variable in Blade:

The Blade:

@extends('layouts.app')

@section('content')

@foreach ($projects as $project)

<p>This is Project Name:  {{ $project->Name }}</p>
<p>This is Project FotoURL:  {{ $project->url }}</p>
<p>--------</p>

@endforeach

@endsection

Error: No Error, but the variables are empty...

Thank you for any feedback!

Kind Regards,

Stefan