Laravel conditionally email validation

I have an array with two relevant keys where at least one of both shall contain a valid email address.

$data = [
 'mail' => 'firstname.lastname#tld.com',
 'mail2' => '[email protected]',
 ...
]

I’ve tried a validation using the exclude_with method, which works if the mail field is invalid but mail2 is valid, however it doesn’t vice versa.

$validated = Validator::make($data, [
    'mail' => 'exclude_with:mail|email',
    'mail2' => 'exclude_with:mail2|email',
])->validate();

I could do this easily with other php methods or regular expressions, but I’m wondering if this is archivable with Laravel’s validator.

The goal is to get at least one field with a valid email or fail.

The Laravel log path has not been updated

In the config folder, I changed the path to the larval log, but the logs are not updated in project.log. it is not working can u help with this please see my below code .

<?php

use MonologHandlerStreamHandler;
use MonologHandlerSyslogUdpHandler;

return [
    'default' => env('LOG_CHANNEL', 'stack'),
    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['daily'],
            'ignore_exceptions' => false,
        ],

        'single' => [
            'driver' => 'single',
            'path' => storage_path('logs/project.log'),
            'level' => 'debug',
        ],

        'daily' => [
            'driver' => 'daily',
            'path' => storage_path('logs/project.log'),
            'level' => 'debug',
            'days' => 14,
        ],

        'slack' => [
            'driver' => 'slack',
            'url' => env('LOG_SLACK_WEBHOOK_URL'),
            'username' => 'Laravel Log',
            'emoji' => ':boom:',
            'level' => 'critical',
        ],

        'papertrail' => [
            'driver' => 'monolog',
            'level' => 'debug',
            'handler' => SyslogUdpHandler::class,
            'handler_with' => [
                'host' => env('PAPERTRAIL_URL'),
                'port' => env('PAPERTRAIL_PORT'),
            ],
        ],

        'stderr' => [
            'driver' => 'monolog',
            'handler' => StreamHandler::class,
            'formatter' => env('LOG_STDERR_FORMATTER'),
            'with' => [
                'stream' => 'php://stderr',
            ],
        ],

        'syslog' => [
            'driver' => 'syslog',
            'level' => 'debug',
        ],

        'errorlog' => [
            'driver' => 'errorlog',
            'level' => 'debug',
        ],
    ],
    'rollbar' => [
            'driver' => 'monolog',
            'handler' => RollbarLaravelMonologHandler::class,
            'access_token' => env('ROLLBAR_TOKEN'),
            'level' => 'debug',
     ],

];

Graphql Conditional Query

How can I conditionally use graphql such that when address is given it returns Account and when it isn’t it retunrs the authenticated user?
accountByAddress(address: String! @where(operator: “like”)): [Account!]! @all

Adding unlimited tabs like google chrome in php

I’m trying to display the tabs based upon the session data, currently I successfully display 3 tabs in total, but now what if just like google chrome I want to display upto N number of tabs…..n?

Is there any way to do this dynamically?

Tabs UI

enter image description here

Using sessions

 $check1 = $this->session->userdata('tabs_1'); //output: 1
 $check2 = $this->session->userdata('tabs_2'); //output: 2
 $check3 = $this->session->userdata('tabs_3'); //output: 3

Html to display tabs

 <ul class="addButton">
   <li >
     <a style="background-color: rgb(35, 82, 124);color: white;cursor: pointer" class="suspendIDCurrent"  data-suspendID="0" id="sus_0">Current</a>
   </li>

 <?php if(isset($check1)):?>
    <li style="margin-left: 9px;" id="btRow_<?=isset($check1) && isset($check2) && isset($check3)?3:1?>">
      <a style="cursor: pointer" class="suspendID" data-suspendID="<?=isset($check1) && isset($check2) && isset($check3)?3:1?>" id="sus_<?=isset($check1) && isset($check2) && isset($check3)?3:1?>">Hold 1</a>
        <span><i class="fa fa-minus deleteSuspendID" data-minusSuspendID="<?=isset($check1) && isset($check2) && isset($check3)?3:1?>"></i></span>
    </li>
 <?php endif;?>
 <?php if(isset($check2)):?>
     <!--only for tab 2-->
     <li style="margin-left: 5px;" id="btRow_2">
      <a style="cursor: pointer" class="suspendID" data-suspendID="2" id="sus_2">Hold 2</a>
        <span><i class="fa fa-minus deleteSuspendID" data-minusSuspendID="2"></i></span>
     </li>
  <?php endif;?>
  <?php if(isset($check3)):?> 
    <li style="margin-left: 5px;" id="btRow_<?=isset($check1) && isset($check2) && isset($check3)?1:3?>">
      <a style="cursor: pointer" class="suspendID" data-suspendID="<?=isset($check1) && isset($check2) && isset($check3)?1:3?>" id="sus_<?=isset($check1) && isset($check2) && isset($check3)?1:3?>">Hold 3</a>
       <span><i class="fa fa-minus deleteSuspendID" data-minusSuspendID="<?=isset($check1) && isset($check2) && isset($check3)?1:3?>"></i></span>
     </li>
     <?php endif;?>
 </ul>

My dynamic approach

 <?php
    //$check = $this->session->userdata('tabs_'.$val);
      $tables_opened = array();
      foreach ($tables as $tbls) { //tabs_ids in array
               if(!empty($this->session->userdata('tabs_'.$tbls->id))){
               $tables_opened[] = $this->session->userdata('tabs_'.$tbls->id);
               }
                           
      }
      print_r($tables_are_on_hold);  //Array ( [0] => 2 [1] => 3 )

how can i get [array] tags recods in php loop

I need some help with my code as I have a hard time with fetching the value from the stdclass. can i get tags data from std array in loop please help me i am stuck here

Array
(
[0] => stdClass Object
    (  
        [gp_package_id_csv] => 
        [ba_hoursperweek] => 40
        [tags] => Array
            (
                [0] => stdClass Object
                    (
                        [KAUFMÄNNISCH] => Sachbearbeitung
                    )

            )
    )
[2] => stdClass Object
    (
        [gp_package_id_csv] => 
        [ba_hoursperweek] => 45
        [tags] => Array
            (
                [0] => stdClass Object
                    (
                        [MARKETING] => Kaufmännisch
                    )

                [1] => stdClass Object
                    (
                        [DIREKTVERMITTLUNG] => Direktvermittlung
                    )

            )
    )
[3] => stdClass Object
    ( 
        [gp_package_id_csv] => 
        [ba_hoursperweek] => 46
        [tags] => Array
            (
            )
    )
)

How to show the icon of success message with Sweetalertjs in the Controller

I’m using Laravel and Sweetalertjs v2 and I wanted to show a success message at the Controller method:

alert(“Submitted successfully”,”submitted”);

And the alert successfully comes up, but the problem is the success icon does not appear.

And in the docs, there is no code for writing an alert and showing and icon type.

It just written this code which is Javascript based and cannot be used in the Controller:

Swal.fire({
  icon: 'error',
  title: 'Oops...',
  text: 'Something went wrong!',
  footer: '<a href="">Why do I have this issue?</a>'
})

So how can I show the icon of alert (success, error, warning, info) at the top of the alert box when using the sweetalert in the Controller method of Laravel?

Change values of the specific key in a multidimensional array

I need to change values of key [productId] in array arr with values from array arr2. The result should be the next:

Array ( [0] => Array ( [productId] =>9404 [stockQuantity] => 10 [incoming] => [prices] => ) [1] => Array ( [productId] =>9401 [stockQuantity] => 15 [incoming] => [prices] => ))

Here is my code:

$data = '[
  {
    "productId": "NPQ10",
    "stockQuantity": 10,
    "incoming": null,
    "prices": null
  },
  {
    "productId": "WS11",
    "stockQuantity": 15,
    "incoming": null,
    "prices": null
    }
]';
  
$arr = json_decode($data, true);
$arr2 = array();
for ($i = 0; $i < count($arr); $i++) { 
    $id = wc_get_product_id_by_sku($arr[$i][productId]);
    array_push($arr2,$id);
}
for($j = 0; $j <= count($arr2); $j++) {
    foreach ($arr as &$entry) {
        foreach ($entry as $key => &$val) {
            if ($key == "productId") {
                $val=$arr2[$j];
            }
        }
   }
}
print_r($arr); 

How to achieve that?

laravel 9 show infos

how can I view the user data of users who write messages?

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;
// use AppModelsPost;
use AppModelsConversation;
use AppModelsMessageReply;
use AppModelsUser;
use Auth;
use DB;
class ConversationController extends Controller
{
   /**
    * Create a new controller instance.
    *
    * @return void
    */
   public function __construct()
   {
       $this->middleware(['auth', 'verified']);
   }

   /**
    * Show the application dashboard.
    *
    * @return IlluminateContractsSupportRenderable
    */
   // public function index()
   // {
   //     $posts = Post::all();
   //     return view('home', compact('posts'));
   // }
   
   public function index()
   {   
       return view('superadmin.conversation.index');
   }
   public function create($title)
   {   
           $user = User::where('id','!=',auth::user()->id)->get();
           return view('conversation',compact('title','user'));
   }
   public function createwithout(){
       $user = User::get();
       $conv = Conversation::select('*')->where('recipients',auth::user()->id)->where('others','M')->get();
       return view('conversation',compact('user','conv')); 
   }
   public function store(Request $request){
               $user = new Conversation();    
               if(!empty($request->input('opt2'))){$opt2 = 1;}else{$opt2 = 0;}
               if(!empty($request->input('opt1'))){$opt1 = 1;}else{$opt1 = 0;}
               if(!empty($request->doc)){
                            $file = $request->file('doc');
                            $doc = rand() . '.' . $file->getClientOriginalExtension();
                            $doc1=$file->move(public_path('/uploadedimages'), $doc);
               }
               else{$doc = 'NIL';}
               foreach ($request->user as $index => $obj) {
                   $categoryS[] = Conversation::create([
                   'recipients' => $obj,
                   'created_by' => Auth::id(),
                   'title' => $request->input('title'),
                   'message' => $request->input('text_editor'),
                   'document' => $doc,
                   'invite_other' => $opt1,
                   'lock' => $opt2,
                   'status'=>'0',
                   'others'=>'M'
                    ]);
           }
           return back();
   }
   public function showlist(){
           $co =   Conversation::where('recipients', '=', auth::user()->id)->update(['status' => 1]);
           $conv = Conversation::select('*')->where('recipients',auth::user()->id)->orWhere('created_by', auth::user()->id)->get();
           return view('conversationlist',compact('conv'));    
   }
   public function updatestatus($id){
           $co = Conversation::find($id);
           $co->status = '1';
           $co->save();
           $conv = Conversation::select('*')->where('id',$id)->get();
           return view('conversationlist',compact('conv'));    
   }
   public function convshow($id){
           $conv = Conversation::select('users.name as name','conversation.*')->leftJoin('users', 'users.id', '=', 'conversation.created_by')->where('conversation.id',$id)->get();
           $reply = MessageReply::select('*')->where('message_id',$id)->get();
           return view('showconversation',compact('conv','reply'));
   }
   public function replytoconv(Request $request){
           $user = new MessageReply();
           MessageReply::create([
                   'message_id' => $request->message_id,
                   'user_id' => Auth::id(),
                   'description' => $request->input('description'),
                    ]);  
           return back();         
   }
}

@extends('layouts.app')
@section('content')
@push('stylesheets')
{{-- <script src="https://cdn.ckeditor.com/ckeditor5/23.0.0/classic/ckeditor.js"></script> --}}

<style>
   .parent-social {
       position: relative;
   }

   .child-social {
       width: auto !important;
       bottom: 0;
       right: 1rem;
       margin: 1rem 0;
   }

   blockquote {
       padding-left: 20px;
       padding-right: 8px;
       border-left: 5px solid #ccc;
       font-style: italic;
       font-family: Georgia, Times, "Times New Roman", serif;
       margin: 13px 40px;
   }

   .reaction-parent {
       position: relative;
       overflow: hidden;
       display: flex;
       justify-content: flex-end;
   }

   .reaction-child {
       width: 135px;
       /* Position the tooltip */
       position: absolute;
       z-index: 1;
       right: 0;
   }

   .reaction-parent i {
       margin-right: 0.5rem;
   }

   .reaction-child .bi {
       font-size: 1.5rem;
   }
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
@endpush
<div class="container-fluid">
   <div class="row no-gutters border m-1 p-2  parent-social">
       <div class="col-12 col-md-2 col-sm-12">
       <div class="card d-flex justify-content-center align-items-center" style="width: 100%;">
               <img src="{{ asset('/uploads/avatar/defaultavatar.webp') }}" class="" alt="..." height="auto"
                   width="75px">
               <div class="card-body">
                   <h5 class="card-title text-center">{{ $conv[0]->name }} <a href="/createconversation/{{$conv[0]->title}}"><span><i class="fa fa-envelope"></i></span></a></h5>
               </div>
               <ul class="list-group list-group-flush">
                   <li class="list-group-item">Joined: {!! date('d-M-y', strtotime($conv[0]->created_at)) !!}</li>
                   <li class="list-group-item">Messages: 0</li>
                   <li class="list-group-item">Reactions: {{ $conv[0]->reactions }}</li>
                   <li class="list-group-item">Vestibulum at eros</li>
               </ul>
           </div>
       </div>
       <div class="col-12 col-sm-6 col-md-10 col-sm-12" style="overflow: hidden;">
           <div class="card-body">
               <h5 class="card-title">{{ $conv[0]->title }}</h5>
           </div>
           <hr class="m-1">
           <div style="overflow-y: scroll; height: 300px; width: 100%; overflow-x: hidden">
               {!! $conv[0]->message !!}
               <img src="{{url('/uploadedimages')}}/{{$conv[0]->document}}" width="120">
           </div>

           <div class="child-social">
               <div class="reaction-parent">
                   <i onclick="showReactions(this)" style="font-size: 1.2rem; cursor: pointer;" id="reaction"></i>
                   <a href="#ckreply" onclick="ckreply({{ json_encode($conv[0]->message, 1) }},{{ json_encode($conv[0]->name, 1) }})" style="color: #000;">
                       <i class="bi bi-reply" style="font-size: 1.2rem;"></i>
                   </a>
               </div>

           </div>
       </div>
   </div>
   @if (isset($reply))
   @foreach ($reply as $reply)
   <div class="row no-gutters border m-1 p-2  parent-social">
       <div class="col-12 col-md-2 col-sm-12">
           <div class="card d-flex justify-content-center align-items-center" style="width: 100%;">
               <img src="{{ asset('/uploads/avatar/defaultavatar.webp') }}" class="" alt="..." height="auto" width="75px">
               <div class="card-body">
                   <h5 class="card-title text-center"></h5>
               </div>

           </div>
       </div>
       <div class="col-12 col-sm-6 col-md-10 col-sm-12" style="overflow: hidden;">
           <div class="card-body">

           </div>
           <hr class="m-1">
           <div style="overflow-y: scroll; height: 300px; width: 100%; overflow-x: hidden">
               {!! $reply->description !!}
           </div>

           <!--<div class="child-social">
                       <div class="reaction-parent">
                           <i onclick="showReactions(this)"
                               class=""
                               style="font-size: 1.2rem; cursor: pointer;"></i>
                           <a href="#ckreply"
                               onclick="ckreply({{ json_encode($reply->description, 1) }},{{ json_encode($reply->description, 1) }})"
                               style="color: #000;">
                               <i class="bi bi-reply" style="font-size: 1.2rem;"></i>
                           </a>
                       </div>
                       
                   </div>-->
       </div>
   </div>

   @endforeach
   @else
   @endif

   <div class="row no-gutters border m-1 p-2" id="ckreply" wire:ignore>
       <div class="col-12 col-md-2 col-sm-12">
           <div class="card  d-flex justify-content-center align-items-center" style="width: 100%;">
               <img src="{{ asset('/uploads/avatar/defaultavatar.webp') }}" class="" alt="..." height="75px" width="75px">
               <div class="card-body">
               <h5 class="card-title text-center">{{ Auth::user()->name }}</h5>
           </div>
               <ul class="list-group list-group-flush">
                   <li class="list-group-item">Joined : {!! date('d-M-y', strtotime(Auth::user()->created_at)) !!}</li>
                   <li class="list-group-item">Messages: 0</li>
                   <li class="list-group-item">Reactions: {{ Auth::user()->reactions }}</li>
                   <li class="list-group-item">Vestibulum at eros</li>
               </ul>
           </div>
       </div>
       <div class="col-12 col-sm-6 col-md-10 col-sm-12 parent-social">
           <form action="/replytoconv" method="post">
               @csrf
               <div class="form-group">
                   <textarea wire:model.defer="description" class="form-control" id="description" name="description"></textarea>
               </div>
               <div class="form-group">
                   <input type="hidden" value="{{$conv[0]->id}}" name="message_id" />
                   <button type="submit" class="btn btn-primary my-2 d-flex justify-content-center align-items-center"> <i class="bi bi-reply" style="margin-bottom: 8px; margin-right: 4px;"></i> Message
                       reply</button>
               </div>
           </form>
       </div>
   </div>
</div>

@push('scripts')
<script src="//cdn.ckeditor.com/4.19.0/standard/ckeditor.js"></script>
<script>
   var ckdata = "";
   var editor = CKEDITOR.replace('description');

   // The "change" event is fired whenever a change is made in the editor.
   editor.on('change', function(event) {

   })
</script>
@endpush

@endsection
@section('scripts')
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous">
</script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous">
</script>
@endsection

I would like to display the data of users who write and reply messages so that it displays :
Joined: 10-Sep-22
Number of messages: 0
Reaction:
Vestibulum in eros

it displays the first user who created the conversation but not after (the person who answers or the one who created the conversation. i tried but I had errors, how could I display so that there is no error?

Using shortcodes for dbquery in wordpress the german quotation marks disapear

I have a mysql table with a text field containing German text with German quotes. E.g. „Freda“.

If I read the database directly via php the result is correct. But when I generate a shortcode in wordpress that contains the same php query of the database, the german quotes disappear. All other characters are displayed.

For this reason i want to change the german quotation marks in the DBfield to ‘„’ ‘“’.

With the following command I can replace the quotes with the entity ‘„’ or ‘“’ using phpmyadmin:

UPDATE `TableName` SET `fieldname` = REPLACE(`fieldname`, '„', '&bdquo;') WHERE `fieldname` LIKE '%„%' COLLATE utf8mb4_bin

But when I want to do this directly using php, I can’t manage it. I can change other characters or words but nothing happens with the quotes. How must the command be formulated in the php file so that I can change it?

I was trying the following codes // as given me from phpmyadmin:

$sql = "UPDATE `TableName` SET `fieldname` = REPLACE(`fieldname`, '„', '&bdquo;') WHERE `fieldname` LIKE '%„%' COLLATE utf8mb4_bin";
$sqlRes = mysqli_query( $db, $sql );

I changed it to:

$sql = "UPDATE `TableName` SET `fieldname` = REPLACE(`fieldname`, '„', '&bdquo;') WHERE `fieldname` LIKE '%„%' COLLATE utf8mb4_bin";
$sqlRes = mysqli_query( $db, $sql );

I changed it to:

$sql = "UPDATE TableName SET fieldname = REPLACE(fieldname, '„', '&bdquo;') WHERE fieldname LIKE '%„%' COLLATE utf8mb4_bin";
$sqlRes = mysqli_query( $db, $sql );

I changed it to:

$sql = "UPDATE TableName SET fieldname = REPLACE(fieldname, '„', '&bdquo;') WHERE fieldname LIKE '%„%' COLLATE utf8mb4_bin";
$sqlRes = mysqli_query( $db, $sql );

But all of this is not working.

I lost my data in other table when I rolled back my migrations in Laravel

So I have a users table that has a one-to-one relationship with a school_members table. I was messing around and rolled back my single last migration and migrated it back right after here’s the file:

use IlluminateDatabaseMigrationsMigration;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateSupportFacadesSchema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->string('jwtv')->default(null)->change();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->string('jwtv')->default('')->change();
        });
    }
};

now mind you my users table and school_members table are related via user id not jwtv, but this action caused me to lose data over at my school_members table and NOT the users table, those data were fine. also there’s many to one relationship between roles and users table via roles id, but roles table are fine. lastly this I do have onDelete('cascade') for the one-to-one relationship.

My goal is trying to understand this so it doesn’t happen to me in the future.

Uncaught ReferenceError: _xxx is not defined – WooCommerce add_to_cart hook

I am using a SERVER-SIDE TRACKING for my woocommerce site.

In there I added a JS Tracking code snippet provided by company to the wp_head using

<script>
   add_action('wp_head', array(
            $this,
            'tracking_code'
        ));
</script>

, and

<script>
    _xxx.push({
       "track"     : "pageview",
    });
</script>

for all other events. All other events are working fine, but when I tried to fire the add to cart, it show the error :

Uncaught ReferenceError: _jts is not defined at ?add-to-cart=12:3:13

What can be the solution for this? Thanks for your time

I want to recive long url from instamojo payment respose script option in a php

I’m integrating the Instamojo payment gateway into a website using core PHP.
I wrote some script that is working well enough on the test.instamojo.com (Which is a test version of their portal) but When I changed the credentials for the live testing (means I have removed test level credentials and put all real-time credentials like their live URL, Private key, Auth Key of our account) It’s started showing error in the variable where I want to receive the long URL to redirect for the payment.

The Instamojo response is

{
    "success": true,
    "payment_request": {
        "id": "47a321d9*****************bbb55f64",
        "phone": "+9170******55",
        "email": "a*******@gmail.com",
        "buyer_name": "Aman",
        "amount": "100.00",
        "purpose": "FIFA",
        "expires_at": null,
        "status": "Pending",
        "send_sms": true,
        "send_email": true,
        "sms_status": "Pending",
        "email_status": "Pending",
        "shorturl": null,
        "longurl": "https://www.instamojo.com/@EXAMPLE/47a321d95c5c4d7f8e0e7742bbb55f64",
        "redirect_url": "http://www.example.com/thankyou.php/",
        "webhook": null,
        "allow_repeated_payments": false,
        "created_at": "2022-09-10T09:16:12.104302Z",
        "modified_at": "2022-09-10T09:16:12.104336Z"
    }
}

This is my Php Code

<?php
$ch = curl_init();
    
curl_setopt($ch, CURLOPT_URL, 'https://www.instamojo.com/api/1.1/payment-requests/');
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER,
            array("X-Api-Key:*****************************************",
                  "X-Auth-Token:**************************************"));
$payload = Array(
    'purpose' => 'FIFA',
    'amount' => '100',
    'phone' => '70*****55',
    'buyer_name' => 'Aman',
    'redirect_url' => 'http://www.example.com/thankyou.php/',
    'send_email' => true,
    'send_sms' => true,
    'email' => 'a******@gmail.com',
    'allow_repeated_payments' => false
);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
$response = curl_exec($ch);
curl_close($ch); 

header('location:'.$response->payment_request->longurl);

?>

I’m getting an error (red line within $ response) at
header(‘location:’.$response->payment_request->longurl);

late static binding in object context

I don’t understand how this example from PHP documentation works :
https://www.php.net/manual/en/language.oop5.late-static-bindings.php
I quote from the doc “In non-static contexts, the called class will be the class of the object instance” means if i add an echo get_class($this) in method test it will display B then C, the first one is then a foo from B (foo is private in A so there is no foo in B), and the second one is a foo from C, and this means it should call the private empty foo from C ? but that’s not it!

<?php
class A {
    private function foo() {
        echo "success!n";
    }
    public function test() {
        $this->foo();
        static::foo();
    }
}

class B extends A {
   /* foo() will be copied to B, hence its scope will still be A and
    * the call be successful */
}

class C extends A {
    private function foo() {
        /* original method is replaced; the scope of the new one is C */
    }
}

$b = new B();
$b->test();
$c = new C();
$c->test();   //fails
?>

Output :

success!
success!
success!
      
Fatal error:  Call to private method C::foo() from context 'A' in /tmp/test.php on line 9

Laraver8: Fullcalendar ver3 add and edit event feature

I am trying to create a calendar with “add event” and “edit event” feature using Fullcalendar.

The problem is that I am able to edit events with the codes shown below but I can’t add new events. After I hit the Add Event button the browser doesn’t show any errors, it just shows a whit blank. I was able to add new events before I changed the codes to add the “edit event” feature.

calendar.blade.php

<body>
    <div id="dialog">
            <div id="dialog-body">
                <form id="dayClick" method="post" action="{{route('eventStore')}}">
                    @csrf
                    <div class="form-group">
                        <label>Event Title</label>
                        <input type="text" id="title" class="form-control" name="title" placeholder="Event Title">
                    </div>
                    <div class="form-group">
                        <label>Start Date/Time</label>
                        <input type="text" id="start" class="form-control" name="start" placeholder="Start date & time">
                    </div>
                    <div class="form-group">
                        <label>End Date/Time</label>
                        <input type="text" id="end" class="form-control" name="end" placeholder="End date & time">
                    </div>
                    <input type="hidden" id="eventId" name="event_id">
                    <div class="form-group">
                        <button type="submit" class="btn btn-success" id="update">Add Event</button>
                    </div>
                </form>
            </div>
        </div>

    <script type="text/javascript">
        $(document).ready(function() {
            var calendar = $('#calendar').fullCalendar({
                editable: true,
                displayEventTime: false,
                selectable: true,
                selectHelper: true,
                header: {
                    left: 'prev,next today ',
                    center: 'title',
                    right: 'myCustomButton'
                },
                events: "{{route('allEvent')}}",
                dayClick: function(date, event, view) {
                    $('#start').val(date);
                    $('#dialog').dialog({
                        title: 'Add Event',
                        width: 600,
                        height: 600,
                        modal: true,
                    })
                },
                select: function(start, end) {
                    $('#start').val(start);
                    $('#end').val(end);
                    $('#dialog').dialog({
                        title: 'Add Event',
                        width: 600,
                        height: 600,
                        modal: true,
                    })
                },
                eventClick: function(event) {
                    $('#title').val(event.title);
                    $('#start').val(event.start);
                    $('#end').val(event.end);
                    $('#eventId').val(event.id);
                    $('#update').html('Update');
                    $('#dialog').dialog({
                        title: 'Edit Event',
                        width: 600,
                        height: 600,
                        modal: true,
                    })
                }
            })
        });
    </script>
</body>

web.php

Route::post('store', [TestController::class, 'store'])->name('eventStore');

TestController.php

public function store(Request $request)
    {
        try {
            if (!empty($request->event_id)) {
                $validator = Validator::make($request->all(), [
                    'title' => 'required',
                    'start' => 'required',
                    'end' => 'required'
                ]);
                if ($validator->failed()) {
                    return redirect()->back();
                } else {
                    if (empty($request->event_id)) {
                        Event::create($request->all());
                        return redirect()->back();
                    } else {
                        Event::where('id', $request->event_id)->update([
                            'title' => $request->title,
                            'start' => $request->start,
                            'end' => $request->end
                        ]);
                        return redirect()->back();
                    }
                }
            }
        } catch (Exception $e) {
            return redirect()->back();
        }
    }

I think there’s something wrong in the web.php but I couldn’t figure out.
Any help or advice would be appreciated as I have tried multiple methods with no success.

Thank you in advance.