Pain12

Pain12

Member Since 3 Months Ago

Experience Points
3,480
Total
Experience

1,520 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
20
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

Level 1
3,480 XP
Mar
26
1 week ago
Activity icon

Replied to Posts In Blade And @forelse With Javascript

Works fine with this. But somehow I can't get the date anymore from this

let from = new Date(Date.parse("2020/3/27" + timefrom));

If I log this I get "Invalid Date".

My code now:

Edit: Nvm mind missed the space ("2020/3/27 " + timefrom);

Activity icon

Replied to Posts In Blade And @forelse With Javascript

why do you put '{{ $timefrom }}' in '' and timer({{ $post->id }} not?

<img onclick="timer({{ $post->id }}, '{{ $timefrom }}', '{{ $timeto }}', '{{ $timenow }}')" >
Activity icon

Started a new Conversation Posts In Blade And @forelse With Javascript

Hey guys, I am trying to make a script for every post I have with the @forelse. The idea is that every time a click on a link an event fires with the data from that specific post.

When I inspect the code in the browser everything looks fine. The script gets duplicated with every Post. But when I click on the link the output is always the result from the latest post.

Does anyone know how do fix that?

@forelse($posts as $post)

// link which toogles a modal
<a><img style="width:100%" onclick="timer()" id="{{$post->id}}"class="z-depth-1 img-thumbnail" src="/uploads/{{$post->image}}" alt="video" data-toggle="modal" data-target="#modal-{{$post->id}}"></a>

//gives me the time from table
<?php
  $timenow = date('H:m:s');
 
  $timefrom = $post->timefrom;
  $timeto = $post->timeto;
  
  ?>
 
//set a timer for the modal to close
  <script>  
      
      let from = new Date(Date.parse("2020/3/26 <?php echo $timefrom ?>"));
      let to = new Date(Date.parse("2020/3/26 <?php echo $timeto ?>"));
      let now = new Date(Date.parse("2020/3/26 <?php echo $timenow ?>"));
      
      let timediffinmilisec = to - now ;

      function timer (){
         if (now >= from && now <= to) {
              var close = function() {
                 $("#modal-{{$post->id}}").modal("hide");
              }
              setTimeout(close, timediffinmilisec);
              alert("window closes in" + msToTime(timediffinmilisec))
              } 
              else 
              {
              document.getElementById("{{$post->id}}").removeAttribute("data-toggle");
              alert("Come back at " + from);
           }
          };

</script>
@endforelse

Output from the browser:

	// Post 1
<a><img style="width:100%" onclick="timer()" id="4"class="z-depth-1 img-thumbnail" src="/png/wohnzimmer.jpg" alt="video" data-toggle="modal" data-target="#modal-4"></a>

      let from = new Date(Date.parse("2020/3/26 23:15:00"));
      let to = new Date(Date.parse("2020/3/26 23:50:00"));
      let now = new Date(Date.parse("2020/3/26 22:03:06"));
      
      let timediffinmilisec = to - now ;

      function timer (){
         if (now >= from && now <= to) {
              var close = function() {
                 $("#modal-4").modal("hide");
              }
              setTimeout(close, timediffinmilisec);
              alert("window closes in" + msToTime(timediffinmilisec))
              } 
              else 
              {
              document.getElementById("4").removeAttribute("data-toggle");
              alert("Come back at " + from);
           }
          };

	//Post 2	
 <a><img style="width:100%" onclick="timer()" id="3"class="z-depth-1 img-thumbnail" src="/png/garten.jpg" alt="video" data-toggle="modal" data-target="#modal-3"></a>

      let from = new Date(Date.parse("2020/3/26 "));
      let to = new Date(Date.parse("2020/3/26 "));
      let now = new Date(Date.parse("2020/3/26 22:03:06"));
      
      let timediffinmilisec = to - now ;

      function timer (){
         if (now >= from && now <= to) {
              var close = function() {
                 $("#modal-3").modal("hide");
              }
              setTimeout(close, timediffinmilisec);
              alert("window closes in" + msToTime(timediffinmilisec))
              } 
              else 
              {
              document.getElementById("3").removeAttribute("data-toggle");
              alert("Come back at " + from);
           }
          };
Activity icon

Replied to Doing Calculation In Js With Php!?

I will look into it. Yes, have nearly 0 experience with js =D What I though I also could do is to do it in php like this:

<?php
  $timenow = strtotime(date('H:m:s'));
 
  $timefrom = strtotime($post->timefrom);
  $timeto = strtotime($post->timeto);
  $timedif= abs($timeto -  $timenow)/(60*60);
  ?>

But somehow that dosent seems to smart. Since I later need to input it to js again

Activity icon

Started a new Conversation Doing Calculation In Js With Php!?

Hey guys, I am trying to work with some data from the database or php in javascript.

What I tried in my blade.php

<?php
  	$timenow = date('H:m:s');

  	$timefrom = $post->timefrom;
 	$timeto = $post->timeto;
 ?>
<script>  
    var time = "<?php echo $timenow ?>";  // var time = "18:03:36";
    var timefrom = "<?php echo $timefrom ?>";  //  var timefrom = "04:04:00";
    var timeto = "<?php echo $timeto ?>";  // var timeto = "23:03:00"; 
    var timedif = "<?php echo $timeto ?> - <?php echo $timenow ?>"; // var timedif = "23:03:00 - 18:03:36"

    $("#{{$post->id}}").click(function(){
        alert(timedif); // alert("23:03:00 - 18:03:36")
    });
</script>

I first get the actual time in php since its way easier to do. The goal is to calculate a time difference. What I don't know is how to tell js to take the difference between the two times. Since for Js everything is a string.

What I tried is to convert the actual time and the time from the DB to an integer in PHP. And then calculate with it in js.

I do all that to tell jquery later that if a timeslot is met it should add or remove certain elements from a div.

Activity icon

Awarded Best Reply on @forelse And Javascript

onclick="myFunction({{$post->timefrom}}, {{$post->timeto}})" 

dosent seem to work. Code stops working when i try to pass the data like that

Edit; Nvm just saw when i put my script it the @forelse loop it copies the script with the right data for every element

Mar
25
1 week ago
Activity icon

Awarded Best Reply on Symlink Over SSH Sharedhosting

I found a short answer to the problem just move the file to the public with

$request->file('photo')->move(public_path("/uploads"), $newfilename);
Activity icon

Replied to Symlink Over SSH Sharedhosting

My whole function looks like this. Just that the validation message doesn't work.

public function store(Request $request)
    {

        $rules = array(
            'title' => 'required',
            'body' => 'required',
            'image' => 'file|image|nullable|max:5000',
            'monday' => 'required_without_all:tuesday,wednesday,thursday,friday,saturday,sunday,immer',
            'tuesday' => 'required_without_all:monday,wednesday,thursday,friday,saturday,sunday,immer',
            'wednesday' => 'required_without_all:monday,tuesday,thursday,friday,saturday,sunday,immer',
            'thursday' => 'required_without_all:monday,tuesday,wednesday,friday,saturday,sunday,immer',
            'friday' => 'required_without_all:monday,tuesday,wednesday,thursday,saturday,sunday,immer',
            'saturday' => 'required_without_all:monday,tuesday,wednesday,thursday,friday,sunday,immer',
            'sunday' => 'required_without_all:monday,tuesday,wednesday,thursday,friday,saturday,immer',
            'immer' => 'required_without_all:monday,tuesday,wednesday,thursday,friday,saturday,sunday'
        );

        $message = array(
            'title.required' => 'The :attribute field is required.');
            // 'title' => 'Titel benötigt' ,
            // 'body' => 'link benötigt',
            // 'image' => '',
            // 'monday' => 'test',
            // 'tuesday' => 'test',
            // 'wednesday' => 'test',
            // 'thursday' => 'test',
            // 'friday' => 'test',
            // 'saturday' => 'test',
            // 'sunday' => 'test',
            // 'immer' => 'test');  
            
        $this->validate($request,$rules,$message);
   
        //Handle File Upload
        if($request->hasFile('image')){
        //Get filename with the extension
        $filenameWithExt = $request->file('image')->getClientOriginalName();
        //Get just filename
        $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
        //Get just ext
        $extension = $request->file('image')->getClientOriginalExtension();
        //Filename to store
        $fileNameToStore= $filename.'_'.time().'.'.$extension;
        //Upload Image to public folder
        $path = $request->file('image')->move(public_path("/uploads"), $fileNameToStore);
        } 
        else 
        {
        $fileNameToStore = 'noimage.jpg';
        }     
    
        // Create Post
        $post = new Post;
        $post->title = $request->input('title');
        $post->body = $request->input('body');

        $post->monday = $request->has('monday') ? 1 : 0;
        $post->tuesday = $request->has('tuesday') ? 2 : 0;
        $post->wednesday = $request->has('wednesday') ? 3 : 0;
        $post->thursday = $request->has('thursday') ? 4 : 0;
        $post->friday = $request->has('friday') ? 5 : 0;
        $post->saturday = $request->has('saturday') ? 6 : 0;
        $post->sunday = $request->has('sunday') ? 7 : 0;
        $post->immer = $request->has('immer') ? true : false;

        $post->timefrom = $request->input('timefrom');
        $post->timeto = $request->input('timeto');

        $post->ort =$request->input('ort');
       
        $post->user_id = auth()->user()->id;
        $post->image = $fileNameToStore;
        $post->save();


        return redirect('/posts')->with('success', 'Post Created');
    }
Activity icon

Replied to Symlink Over SSH Sharedhosting

	$filenameWithExt = $request->file('image')->getClientOriginalName();
        //Get just filename
        $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
        //Get just ext
        $extension = $request->file('image')->getClientOriginalExtension();
        //Filename to store
        $fileNameToStore= $filename.'_'.time().'.'.$extension;

My first post =D

Activity icon

Replied to Symlink Over SSH Sharedhosting

I found a short answer to the problem just move the file to the public with

$request->file('photo')->move(public_path("/uploads"), $newfilename);
Activity icon

Replied to Symlink Over SSH Sharedhosting

hmm it still uploads in the storage folder. Maybe I need to clear the cash or something? The upload lands in storage/app/public/uploads if I use

$path = $request->file('image')->storeAs('uploads', $fileNameToStore, 'public');
      'public' => [
            'driver' => 'local',
            'root' => public_path(),
            'url' => env('APP_URL'),
            'visibility' => 'public',
        ],

what I found is this : https://stackoverflow.com/questions/44577380/how-to-upload-files-in-laravel-directly-into-public-folder

But when I create a new disk and try to use it with

storeAs('uploads', $fileNameToStore, 'public');

I get the error

Disk [public_uploads] does not have a configured driver.

New disk

 'public_uploads' => [
            'driver' => 'local',
            'root'   => public_path() . '/uploads',
        ],

new function

$path = $request->file('image')->storeAs('', $fileNameToStore,'public_uploads');

Edit: found https://laracasts.com/discuss/channels/laravel/image-upload-using-storage-function-to-public-folder Will try

Edit2: For me worked

$request->file('photo')->move(public_path("/uploads"), $newfilename);
Activity icon

Replied to Symlink Over SSH Sharedhosting

@snapey Symlinks are not allowed on the server that why I am now trying to upload the file directly to the public path. But if i use

 $path = $request->file('image')->storeAs('public/uploads', $fileNameToStore);

it always stores the file in the storage folder even if I change the disks to something like this.

'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => public_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => public_path('app/public'),
            'url' => env('APP_URL').'/public',
            'visibility' => 'public',
        ],

How should my function and disk looks like if i want to use the

storeAs function?
Mar
24
1 week ago
Activity icon

Replied to Symlink Over SSH Sharedhosting

@snapey removing the dot didn't change anything. The link in the browser is src="/storage/uploads/chip_1585082904.jpg" and if I pas the link in the browser I get the error:

Server Error
403
Forbidden
You do not have permission to access this document.

@jlrdw why would my .env file be exposed? My Laravel project is over the folder public. MyProject/public -> here is where I linked the hosting to look for the index.html

And on localhost everything works fine. Pushed it to git and installed everything on the webserver. Same folder structure.

Activity icon

Replied to Symlink Over SSH Sharedhosting

my controller looks like this

if($request->hasFile('image')){
        //Get filename with the extension
        $filenameWithExt = $request->file('image')->getClientOriginalName();
        //Get just filename
        $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
        //Get just ext
        $extension = $request->file('image')->getClientOriginalExtension();
        //Filename to store
        $fileNameToStore= $filename.'_'.time().'.'.$extension;
        //Upload Image
        $path = $request->file('image')->storeAs('public/uploads', $fileNameToStore);
        } 
        else 
        {
        $fileNameToStore = 'noimage.jpg';
        }

$post->image = $fileNameToStore;
$post->save();

And I try to view the file with

<a><img style="width:100%" onclick="test()" id="{{$post->id}}"class="z-depth-1 img-thumbnail" src="./storage/uploads/{{$post->image}}" alt="video"
                        data-toggle="modal" data-target="#modal-{{$post->id}}"></a>

so yes file is named storage/upload/imagename.png

Activity icon

Started a new Conversation Symlink Over SSH Sharedhosting

Hey guys, I have a website on a shared hosting provider. But my file upload doesn't work properly. The file is successfully uploaded to the folder storage/app/public/uploads but it doesn't show on my site if I call the file. On localhost everything works fine

What I did to deploy the website is.

Login over SSH:
-git pull my project
-install everything necessary
and then I ran 
php artisan storage:link

in my Laravel project folder.

My public folder is still inside the laravel folder as default. Nothing changed from the folder structure. In the option of the web host I set the target folder of the domain to the laravelproject/public.

When I log in via FTP everything seems fine. When I click on the storage folder in public it redirects me to storage/app/public.

Does anyone know why this can happen? Could it be that symlinks are deactivated on this shared hosting server? And if yes what would be the alternative that is secure.

Mar
23
1 week ago
Activity icon

Replied to Validation Of Many Fields

and what is wrong? I mean the validation works. I need to input on field but can also input many.

Activity icon

Awarded Best Reply on Deploying Laravel Error

Nvm. Worked with SSH. Dunno where the problem was but works fine now.

Activity icon

Replied to Deploying Laravel Error

Nvm. Worked with SSH. Dunno where the problem was but works fine now.

Activity icon

Started a new Conversation Deploying Laravel Error

Hey guys, I tried to deploy my project to shared hosting. What I did is this:

I. copied my project accept for the public folder to a folder called familyshare
II. copied the public folder to folder called httpdocs which is where my domain is linked to.
III. changed in the index.php in the now httpdocs folder the lines to
/*require __DIR__.'/../vendor/autoload.php';*/
require __DIR__.'/../familyshare/vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
/*$app = require_once __DIR__.'/../bootstrap/app.php';*/
$app = require_once __DIR__.'/../familyshare/bootstrap/app.php';

Now if I try to open the website I get the this error

View [pages.index] not found.

So somehow it is still not linked correctly? You can visit the site http://family-share.de/ to see the error.

Hope someone can help =D

Mar
20
2 weeks ago
Activity icon

Replied to Validation Of Many Fields

@shez1983 The user can choose between days a post should be viable. So Monday and Tuesday works fine. Or Monday, Tuesday, sunday

@snapey will try ur suggestion

Activity icon

Replied to Validation Of Many Fields

So I tried the long way and the validation work fine but the custom massage don't work. I tried few things but I always get the laravel standard error.

   public function store(Request $request)
    {

        $rules = array(
            'title' => 'required',
            'body' => 'required',
            'image' => 'file|image|nullable|max:5000',
            'monday' => 'required_without_all:tuesday,wednesday,thursday,friday,saturday,sunday,immer',
            'tuesday' => 'required_without_all:monday,wednesday,thursday,friday,saturday,sunday,immer',
            'wednesday' => 'required_without_all:monday,tuesday,thursday,friday,saturday,sunday,immer',
            'thursday' => 'required_without_all:monday,tuesday,wednesday,friday,saturday,sunday,immer',
            'friday' => 'required_without_all:monday,tuesday,wednesday,thursday,saturday,sunday,immer',
            'saturday' => 'required_without_all:monday,tuesday,wednesday,thursday,friday,sunday,immer',
            'sunday' => 'required_without_all:monday,tuesday,wednesday,thursday,friday,saturday,immer',
            'immer' => 'required_without_all:monday,tuesday,wednesday,thursday,friday,saturday,sunday'
        );

        $message = array(
            'title.required' => 'The :attribute field is required.');
            // 'title' => 'Titel benötigt' ,
            // 'body' => 'link benötigt',
            // 'image' => '',
            // 'monday' => 'test',
            // 'tuesday' => 'test',
            // 'wednesday' => 'test',
            // 'thursday' => 'test',
            // 'friday' => 'test',
            // 'saturday' => 'test',
            // 'sunday' => 'test',
            // 'immer' => 'test');  
            
        $this->validate($request,$rules,$message);
Activity icon

Replied to Validation Of Many Fields

true =D But when I have a question like this and I want to know other alternatives or more simple or pretty ones I want to know the answer first before I start =D

Bad habit?

Activity icon

Replied to Validation Of Many Fields

OK but then I don't check if one of the checkboxes was checked right?

I want to validate that one of the 7 checkboxes needs to be checked.

Activity icon

Started a new Conversation Validation Of Many Fields

Hey guys, how do I validate 7 fields without writing a ton? I found this for the validation of three fields.

$rules = array(
    'facebook_id' => 'required_without_all:twitter_id,instagram_id',
    'twitter_id' => 'required_without_all:facebook_id,instagram_id',
    'instagram_id' => 'required_without_all:facebook_id,twitter_id',
);
$message = array(
    'facebook_id' => 'The facebook field is required when none of twitter / instagram are present.',
    'twitter_id' => 'The twitter field is required when none of facebook / instagram are present.',
    'instagram_id' => 'The instagram field is required when none of twitter / facebook are present.');

$validator = Validator::make(Input::all(), $rules, $message)->validate();

But if i have 7 fields lets say one for every day of the week like this:

 <input type="checkbox" name="monday">
 <input type="checkbox" name="tuesday">
 <input type="checkbox" name="..">
....

How do I do it without writing every day like this:

 $rules = array(
    'monday' => 'required_without_all:tuesday,.....,....,...',
    'tuesday' => 'required_without_all:monday,....',
    '....' => 'required_without_all:monday,tuesday,....',
);
Mar
14
3 weeks ago
Activity icon

Replied to Authentication Inside An Authentication

Do u have a link for an admin user tutorial?

Activity icon

Replied to Authentication Inside An Authentication

yes, but I want the person who creates the account first to set a password on the profile page for example and then he shares his account with others. So they get the password for the login but can't access the profile page.

The idea is that one person manages content for one or more people.

Activity icon

Started a new Conversation Authentication Inside An Authentication

Hello guys, I have an App where people can share one account. But I want to put another authentication in front of the admin panel of this account so only the owner can change content or the profile picture and so on.

I am using the Laravel authentication for the normal login. How can I integrate another login for one page?

Mar
07
4 weeks ago
Activity icon

Replied to Empy Database

ok found the problem. Had nothing to do with the new columns. When I input nothing in timefrom and timeto I get an error cause I use

$timefrom = str_replace(":", ".",$request->get('timefrom'));
$timeto = str_replace(":", ".",$request->get('timeto'));

$post->timefrom = $timefrom;
$post->timeto = $timeto;

If i understand it correctly if I have nothing as input str_replace() give me back an empty string? And if my DB is

$table->decimal('timefrom')->nullable();
            $table->decimal('timeto')->nullable();

I get the error?

Fixed it with

  if (empty($request->get('timefrom')) || empty($request->get('timefrom'))) {
            $timefrom = $request->get('timefrom');
            $timeto = $request->get('timeto');
        } else{
            $timefrom = str_replace(":", ".",$request->get('timefrom'));
            $timeto = str_replace(":", ".",$request->get('timeto'));
        }
Activity icon

Started a new Conversation Empy Database

Hey guys, I have a post table and want 2 tables (request and online) in there to be empty so I can input some data later.

Schema::create('posts', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id');
            $table->string('title');

            $table->boolean('request')->nullable();
            $table->boolean('online')->nullable();

            $table->timestamps();
        });

But when i try to create a post and dont input any data i get an error. Also, I don't have any HTML input for these 2 columns.

$post = new Post;
        $post->title = $request->input('title');
 	$post->user_id = auth()->user()->id;
        $post->save();

I thought since I have nullable in my migration I don't need to input any data.

Here my error. My table is a bit bigger than above. Just rimmed abit for this post.

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect decimal value: '' for column `familyshare2`.`posts`.`timefrom` at row 1 (SQL: insert into `posts` (`title`, `body`, `monday`, `tuesday`, `wednesday`, `thursday`, `friday`, `saturday`, `sunday`, `immer`, `timefrom`, `timeto`, `anfrage`, `online`, `user_id`, `updated_at`, `created_at`) values (Badezimmer, //link..fwsafaws, 0, 0, 0, 0, 0, 0, 0, 1, , , 0, 0, 1, 2020-03-07 21:41:51, 2020-03-07 21:41:51))
Mar
05
4 weeks ago
Activity icon

Replied to Working With Php In Javascript

thank u very much. Jear, need alot of training 😊 Just started this semester with everything.

Mar
04
1 month ago
Activity icon

Replied to Working With Php In Javascript

haha thanks u guys. Yes I though about calculating in php and then pass it to js. But was wondering how to do it like that.

Also later I want to compare the calucalted data in js to run functions based on it.

Activity icon

Started a new Conversation Working With Php In Javascript

Working in an blade.php

<?php
  $date = date("Y-m-d");
  $time = date("H:i:s");
 ?>

  <script>

    function myFunction() {
          var time = <?php echo json_encode($time) ?>;
          var timefrom = <?php echo json_encode($post->timefrom) ?>; 
          var timeto = <?php echo json_encode($post->timeto) ?>; 
		
	  var date_dif = timeto - date;
	  alert(date_dif);

  </script>

Alert gives me back "NaN".

Source in the browser looks like that:

function myFunction() {
          var time = "21:14:53";
          var timefrom = "21:21:00"; 
          var timeto = "23:00:00"; 

          var date_dif = timeto - time;
         
          alert(date_dif);

So data is getting passed but not saved? Has anyone any idea how I can work with the data I pass from PHP to javascript?

Activity icon

Replied to @forelse And Javascript

onclick="myFunction({{$post->timefrom}}, {{$post->timeto}})" 

dosent seem to work. Code stops working when i try to pass the data like that

Edit; Nvm just saw when i put my script it the @forelse loop it copies the script with the right data for every element

Activity icon

Replied to @forelse And Javascript

thy I will trie it later

Mar
03
1 month ago
Activity icon

Started a new Conversation @forelse And Javascript

Hey guys, maybe you can help me understand how @forelse is or is not working for javascript.

My situation is something like this.

I have a forelse loop

@forelse($posts as $post)
           <a><img onclick="myFunction()" id="{{$post->id}}" src="/png/videoplayer.jpg" alt="video"
  		    data-toggle="modal" data-target="#modal-{{$post->id}}"></a>
			
	 	   opens modal with:
<h4>From {{$post->timefrom}} to {{$post->timeto}}</h4>
...

that gives me all my posts from my user through the controller.

Now I want to use a script on every post, that tests some stuff. My problem is that my script doesn't loop through all my posts even when I place the script in the forelse loop. My script only give the last post. So I think it just runs throw all posts and outputs the last one/ or first one depending on what is written in the controller.

I could create a separate loop for the script but how would I connect the script with the output above? The script could be something like that.

function myFunction() {
         var test = "{{$post->timefrom}}"; 
         var test2 = "{{ $post->timeto }}"; 
         
         alert("start datum = " + test  + " end datum = " + test2 );

Now when I click on the link I want my script to run and give me an alert with my variables that should exactly be the same as above.

Hope you understand what I mean =D Basically match my data in the html and my script

Mar
02
1 month ago
Activity icon

Replied to Passing Data Through Blade To Javascript?

"@pain12 you forgot the quotes: var test = "{{ $post->title }}";. Curly braces is just a shorthand for . "

ohh didn't know that. Thanks

To rephrase my questions.

With a for else loop, I get every element from my database. Now I want my script to also loop through the same. But my variable outputs only the first entry of my database. Even when I put the script in the forelse loop.

So my html goes throw all entrys with

 @forelse($posts as $post)
<div class="col-lg-4 col-md-12 mb-4"> <!-- mb = margin bottom-->
            <h4>Stream: {{$post->title}}</h4>
            <h4>Verfügbar von {{$post->timefrom}} bis {{$post->timeto}}</h4>......
..........................................................
 @endforelse

And if i want my script to do the same. How would I start?

<script>
function myFunction() {
var test = "{{$post->title}}"; 
var test2 = "{{$post->timefrom}}";
}
</script>
Activity icon

Started a new Conversation Passing Data Through Blade To Javascript?

Hey guys, I'm trying to pass some data from a table to a javascript var.

The way I found to do it would be with https://github.com/laracasts/PHP-Vars-To-Js-Transformer But I was wondering if there is a more direct way.

My blade looks something like this

 @forelse($posts as $post)
<div class="col-lg-4 col-md-12 mb-4"> <!-- mb = margin bottom-->
            <h4>Stream: {{$post->title}}</h4>
            <h4>Verfügbar von {{$post->timefrom}} bis {{$post->timeto}}</h4>......
..........................................................
 @endforelse

After this comes a javascript for that I need data from a table. And I was wondering if I can pass data like this.

Var test = {{$post->title}};  

But that doesn't seem to work. Also if I am trying to pass {{$post->title}} to a PHP var it also doesn't work. So I was wondering if there a way to do it with eloquent?

Feb
29
1 month ago
Activity icon

Replied to Closing Modal With Timeout Based On Data From A Table

ohh thanks. Found my error =D

And how would I pass data from my table in a variable?

I use a @forelse($posts as $post) loop in my blade

Activity icon

Started a new Conversation Closing Modal With Timeout Based On Data From A Table

Hello guys, I am trying to write a script for a blade.view that close a modal based on a timer that is calculated from data in my database. My idea was since I have a table with 2 inputs. For example "15:00" and "18:00". And at this time my modal should be openable I can calculate the time until it should close. So basically if time now for example "timenow" < "15:00"(from the table) then close window. If timenow > "15:00" and < "18:00" then calculate the time till closing. 18:00 - timenow and input that in a timeout function.

What I got so far is this.

 <a><img onclick="myFunction()"........</a>

function myFunction() {

      var d = new Date();
      var s = d.getSeconds();
      var timestart = 5000; // should be the data from the table
      var timeend = 10000; // here i want to import my data from a table and contert it in seconds
      var time = timeend - s;

      if (s >= timestart && s < timeend) {
          var close = function() {
              $("#2").modal("hide");
              alert(time + "seconds til closing modal");
          }

          setTimeout(close, time); // closing the modal in calculated time

      } else {

          $("#2").modal("hide");
          alert("opens in" + timestart + "seconds");
      }
  }

Since I am quite new to js I find it quite difficult to pinpoint where my code doesn't work. Maybe some of you can help =D

There are a few other points I don't know how to do. I How to do I input data in a variable from a table II Can I input a blade syntax as id? Like this?

$("#modal-{{$post->id}}").modal("hide");
Activity icon

Replied to OrWhere

Thank you.

Activity icon

Replied to OrWhere

OK nice. But I get the error "Undefined variable: today". So somehow it can't find my defined

$today = strToLower(now()->format('l'));

variable now.

My whole function looks like this:

  public function index()
    {

        $today = strToLower(now()->format('l'));

        $posts = auth()->user()->posts()
        ->latest()
        ->where(function($query) {
            $query->where($today,'<>',0)
                  ->orwhere('immer','=','1');
        })
        ->paginate(10);
                                                    
       
        return view('posts.index')->with('posts', $posts);
       
    }

Feb
28
1 month ago
Activity icon

Started a new Conversation OrWhere

Hey guys, I am trying something like this:

$today = strToLower(now()->format('l'));
$posts = auth()->user()->posts()->latest()->where($today,'<>',0)->orwhere('immer','=','1')->paginate(10);
       
return view('posts.index')->with('posts', $posts);

What is happening is now that the first where the statement works fine. I only get the posts from the specific user. But the second where clause gives back all tables with the name 'immer' with the value 1 from All users.

Does anyone have any idea how to fix this?

Feb
17
1 month ago
Activity icon

Replied to CSS Mixing

Yes in theory. But that not what is happing. In picture 1. u see the style.css overwriting the bootstrap. And that what I want. But picture 2 shows that somehow I doesn't overwrite bootstrap anymore on some specific pages.

Activity icon

Started a new Conversation CSS Mixing

Hello guys, I had something similar happen before but now it happened again. I have some blade files in my laravel projects that somehow uses different CSS elements even though all start with @extends('layouts.app') @section('content') and are placed in the body tag. In my App.blade I import these files.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link href="lib/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet"> 

When I view my side in the browser and inspect it I get these.

Bilder-Upload.eu - share DEINE Bilder And

Bilder-Upload.eu - share DEINE Bilder

The first picture has everything how it should be. Right navbar...

The second picture somehow uses the maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css even though its placed at the top and the style.css should have priority over it.

Anyone know why this is happening?

Jan
24
2 months ago
Activity icon

Replied to Blade.php Styling Issue

Well, I found the difference but not why this is only happening in these two files. I have 2 CSS files and somehow one overwrite the others? I don't know. Normally the style should be everywhere be the same right? If I use @extends('layouts.app') @section('content') @endsection

Jan
23
2 months ago
Activity icon

Started a new Conversation Blade.php Styling Issue

Hello guys, I have a few blade files and everyone except for 2 show the right styling. So my view consists of these folders

pages: about, index
posts: create, edit, index
and 2 files outside of folders.

What I mean is that on the create and edit. blade file the navbar is not inline. See picture. Bilder-Upload.eu - share DEINE Bilder https://www.bilder-upload.eu/bild-8432b5-1579821207.jpg.html

I checked for custom style in the blade file and even removed the content except or the

@extends('layouts.app')
@section('content')
@endsection

content. But nothing changed. Does anyone have an idea why this is happening? I mean the index.blade in the folder works. Just the 2 files or broken.

Jan
20
2 months ago
Activity icon

Replied to Where Do I Convert Data

true, but I wanted to match the now() function which gives me days like 1,2,3.... Now I tried to apply the data to a edit.form where a checkbox should be checked if a monday=1. But to do that I need true/false values.

Activity icon

Replied to Middleware/Controller Filter Output

ok, so if I want to always check the time, I need to build a middleware? And then somehow filter the videos I want to see. So quare one again 😭

Activity icon

Started a new Conversation Where Do I Convert Data

Hey guys, I want to use some data from my table but it needs to be converted. I have something like 1/0,2/0,3/0,4/0 in my table and want to convert it to true/false depending on the data, so I can use the new variables in the blade.php.

Maybe create a function in the controller? Would this work?

public function convert(Request $id)
    {
    $post = Post::find($id);

    if($post->monday = 1){
        $mo = true;
    } else{
        $mo = false;
    }
    }
Activity icon

Replied to Middleware/Controller Filter Output

Ok very good. But let's say I am watching a video at 23.59. I assume that nothing will happen at 00.01 until I refresh the page? Or does a middlewarere refresh every second?

Edit: and what does this

format('l'))

do? I only found this:

format('l')      // 6/9/2014 

and this is from Moment.js