konrms

konrms

Member Since 10 Months Ago

Experience Points
2,790
Total
Experience

2,210 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
9
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.

Level 1
2,790 XP
Nov
04
1 week ago
Activity icon

Replied to Dns Issues For Live Server Environment

@sinnbeck thanks for your advice!

I just solved it by only altering the welcome.blade href links.

For example I changed the following code excerpt

<h2>
<p>1) <a href = "http://laravel.site/startpage">page1</a></p>
<p>2) <a href = "http://laravel.site/sxoles">page2</a></p>

...

</h2>

to

<h2>
<p>1) <a href = "/startpage">page1</a></p>
<p>2) <a href = "/sxoles">page2</a></p>

...

</h2>

Now, each user accesses the site with numeric ip and when browsing to sub-areas he is redirected to numeric ip/[page]

For example the home page is 180.130.120.50. Clicking on link redirects now (correctly) to 180.130.120.50/startpage which is what I wanted. I guess now my n/w administrator should add ip to the dns server!

Activity icon

Replied to Dns Issues For Live Server Environment

Hi @sinnbeck

I altered .env and the section now looks like this:

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:cg+Ht2BY0RWLVj6N+pM+xXIGPCG7plZpnP+a4wlgxmA=
APP_DEBUG=true
APP_URL=180.130.120.50   // this was APP_URL=http://localhost

Then cleared cache but the issue persists. I also flushed dns from my windows machines but it didn't help too.

Activity icon

Started a new Conversation Dns Issues For Live Server Environment

Hi guys,

All LAN computers can access my laravel site on my centos 7 server via the server numeric IP address. But each time a user wants to go to laravel site sub-areas, the numeric address is missed from their browser address bar.

For example browsing to 180.130.120.50 from a LAN pc redirects to laravel home page. When a user wants to open a page of the site, he/she is redirected to laravel.site/[route], eg laravel.site/page1. They can only access page if they correct address as 180.130.120.50/[route], eg 180.130.120.50/page1

I have done (with no success) the following changes on my server::

  1. I have edited the last lines of /etc/httpd/conf/httpd.conf file as below:
<<VirtualHost *:80>
       ServerName 180.130.120.50      ###--> this was previously set to laravel.site
       DocumentRoot /var/www/laravel/public

       <Directory /var/www/laravel>
              AllowOverride All
       </Directory>
</VirtualHost>
  1. I have edited /etc/hosts file
127.0.0.1   180.130.120.50 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         l180.130.120.50 localhost localhost.localdomain localhost6 localhost6.localdomain6

Previously instead of 180.130.120.50 I had set laravel.site as below:

127.0.0.1   laravel.site localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         laravel.site localhost localhost.localdomain localhost6 localhost6.localdomain6

(The guide I had initially followed for laravel installation was this https://tecadmin.net/install-laravel-framework-on-centos/ and the problem has to do with step 6.)

Thank you A LOT!

Nov
02
1 week ago
Activity icon

Replied to Oci8 Exception - Laravel On Centos 7

Hi @aurawindsurfing

After a lot of hours of googling I found that I should also add the Environmental Variables for the Apache Service in /etc/sysconfig/httpd. This link helped me a lot: https://ilanea.net/connect-to-oracle-db-with-instantclient-php7-oci8-centos-7/

So, for my case I should just point to oracle position. This resolved the problem and queries finally ran successfully:

ORACLE_HOME=/home/data/oracle/12c/dbhome_1
PATH=$PATH:$ORACLE_HOME/bin
LD_LIBRARY_PATH=$ORACLE_HOME/lib
TNS_ADMIN=$ORACLE_HOME/network/admin

I had thought of adding the extension=oci8.so to php.ini as I had done in windows. But it caused a warning that oci8 was already loaded when starting the Apache server:

service httpd start

Thanks a lot for replying!

Oct
30
1 week ago
Activity icon

Started a new Conversation Oci8 Exception - Laravel On Centos 7

Hello guys. My project runs fine on windows using xampp. Now I try to implement it on a live server environment and I have come across a few issues (I have asked the same on stackoverflow too) . My OS is CENTOS 7 Server. The Database version is the oracle 12c release2 and my Laravel version is the 5.7.28

I have installed php and oci8 and the necessary yajra package for laravel to oracle connectivity. The table models were integrated in the framework from the initial projects and when ran

php artisan migrate

the tables were successfully migrated into my database as hopefully expected. However, when running the project and the query is called via laravel controller I get this error:

Yajra \ Pdo \ Oci8 \ Exceptions \ Oci8Exception

With the following error description:

/var/www/laravel/vendor/yajra/laravel-pdo-via-oci8/src/Pdo/Oci8.php

         * @param string $dsn
         * @param string $username
         * @param string $password
         * @param array  $options
         * @param string $charset
         * @throws Oci8Exception
         */
        private function connect($dsn, $username, $password, array $options, $charset)
        {
            $sessionMode = array_key_exists('session_mode', $options) ? $options['session_mode'] : null;

            if (array_key_exists(PDO::ATTR_PERSISTENT, $options)) {
                $this->dbh = @oci_pconnect($username, $password, $dsn, $charset, $sessionMode);
            } else {
                $this->dbh = @oci_connect($username, $password, $dsn, $charset, $sessionMode);
            }

            if (! $this->dbh) {
                $e = oci_error();
                throw new Oci8Exception($e['message']);
            }
        }

My .env file section for oracle database connectivity is this:

DB_CONNECTION=oracle
DB_HOST=localhost
DB_PORT=1521
DB_DATABASE=orcl
DB_SID_ALIAS=konrms
DB_USERNAME=korms
DB_PASSWORD=Any_password!
DB_CHARSET=AL32UTF8

Is it possible oci8 not to be working as expected? In that case I guess migration would fail... Furthermore I don't know how if it is necessary to add $dsn variable to my .env.

Sep
10
2 months ago
Activity icon

Replied to Formatting Exported Excel File

Hi SKAUK,

I finished with the project. You helped me a lot! Thanks again!

Sep
09
2 months ago
Activity icon

Replied to Formatting Exported Excel File

Hi SKAUK.

Thank you very much for your points,

I finally applied the following solution, since I needed to format some intermediate rows.

I still need to add all border style to all the cell of the excel. How can I edit $styleArray to create the border I need?

<?php

namespace App\Exports;

use App\Member;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings; 
use Maatwebsite\Excel\Concerns\ShouldAutoSize;

use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;

class MembersExport implements FromCollection, WithHeadings, ShouldAutoSize, WithEvents
{
    
    public function collection()
    {
        return Member::all();
    }
    
    public function headings(): array
    {
        return 
        [
            'head1',
            'head2',
            'head3',
            'head4',
            'head5',
            'head6',
            'head7',
        ];
    }
    
     public function registerEvents(): array
    {
        
        $styleArray = [
        'font' => [
        'bold' => true,
        ]
        ];
            
        
        
        return [
            AfterSheet::class    => function(AfterSheet $event) use ($styleArray)
            {
                $cellRange = 'A1:G1'; // All headers
                //$event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setName('Calibri');
                $event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setSize(14);
                $event->sheet->getStyle($cellRange)->ApplyFromArray($styleArray);
                $event->sheet->getStyle('A9:G9')->ApplyFromArray($styleArray);
                $event->sheet->getStyle('A12:G12')->ApplyFromArray($styleArray);
                $event->sheet->getStyle('A19:G19')->ApplyFromArray($styleArray);
                $event->sheet->getStyle('A27:G27')->ApplyFromArray($styleArray);
                $event->sheet->getStyle('A31:G31')->ApplyFromArray($styleArray);
                $event->sheet->getStyle('A35:G35')->ApplyFromArray($styleArray);
                $event->sheet->getStyle('A36:G36')->ApplyFromArray($styleArray);
                $event->sheet->getStyle('A42:G42')->ApplyFromArray($styleArray);
                $event->sheet->getStyle('A43:G43')->ApplyFromArray($styleArray);
            },
        ];
    }
    
    
    
}
Activity icon

Started a new Conversation Formatting Exported Excel File

Hello guys!

I use the maatwebsite/excel package to produce excel files from database tables. The export is successful, but I need some help with formatting it.

In fact I want the excel to have bigger font size for headings, highlighted headings and borders.

So far I have succeeded only in creating bigger size header fonts using setSize() as you can see in my code excerpt.

My exports file (C:\xampp\htdocs\laravel\app\Exports\MembersExport.php) is the following:

<?php

namespace App\Exports;

use App\Member;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings; 
use Maatwebsite\Excel\Concerns\ShouldAutoSize;

use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;

class MembersExport implements FromCollection, WithHeadings, ShouldAutoSize, WithEvents
{
    
    public function collection()
    {
        return Member::all();
    }
    
    public function headings(): array
    {
        return 
        [
            'head1',
            'head2',
            'head3',
            'head4',
            'head5',
        'head6',
        'head7',
        ];
    }
    
     public function registerEvents(): array
        {
        return [
            AfterSheet::class    => function(AfterSheet $event) 
            {

                       $cellRange = 'A1:G1'; // All headers
                       $event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setName('Calibri');
               $event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setSize(14);

        
            },
              ];
       }
    
    
    
}

For example I have found the following code in a guide. How can I integrate it in the excerpt above?

$styleArray = [
    'borders' => [
        'outline' => [
            'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK,
            'color' => ['argb' => 'FFFF0000'],
        ],
    ],
];

$worksheet->getStyle('A1:G1')->applyFromArray($styleArray);

Thanks a lot!

Jul
11
4 months ago
Activity icon

Replied to Forbidding Access To Database While Another User Requests Data From It

Hi guys!

I finished with my project successfully a few days ago and I want to share the solution I came up with, in case someone else's does something relevant.

I want to thank @snapey, @tray2, @jlrdw... Guys thank you so much for your recommendations!

The solution to the problem is to create random named tables. My initial approach to create tables with Str::random generated names didn't work since some strings started with a numeric character and oracle db didn't accept it..

So I created an extra subfolder helpers (C:\xampp\htdocs\laravel\app\Helpers) and put the file SLcM_Helper.php inside which sets the pool range of generated characters:

<?php

namespace App\Helpers;

use Illuminate\Support\Facades\Schema;
use DB;

class SLcM_Helper
{
    public function CreateRandomText($starting_string, $length)
    {
        $characters = 'abcdefghijklmnopqrstuvwxyz';
        $charactersLength = strlen($characters);
        $randomname = 'a'.$starting_string.'_'; 
        for ($i = 0; $i < $length; $i++) {
            $randomname .= $characters[rand(0, $charactersLength - 1)];
        }
        return $randomname;
    }



    public static function instance()
    {
        return new SLcM_Helper();
    }

    }

Now back to my controller, I call this simply as below:

$table_a = \App\Helpers\SLcM_Helper::instance()->CreateRandomText('a', 10);  //random string starts with 'a'  

//And create the table:

Schema::create($table_a, function (Blueprint $table) 
            {
                $table ->integer('id') -> nullable(); 
                $table ->string('LANGUAGE') -> nullable();
                $table ->float('mark') -> nullable();
            });

As @snapey suggested, inside the raw queries the table is accessed by " .$table_a.",

eg

$first_name = DB::select("select users.first_name from users, ".$table_a." where  ......... ");
Jul
01
4 months ago
Activity icon

Replied to Forbidding Access To Database While Another User Requests Data From It

@SNAPEY - Thanks a lot! This worked.

DB::statement('alter table ' .$ppdf. ' add marktotext VARCHAR2(256)');
Activity icon

Replied to Forbidding Access To Database While Another User Requests Data From It

Hello my friends!

I think that my problem will be resolved if I make it to give the basic table I use in my code a random name. Testing will prove if I'm right ;).

I have managed to give this as below:

$ppdf = Str::random(10); //number of alphanumeric characters
$ppdf = strtoupper($ppdf); // string to uppercase

Schema::create($ppdf, function (Blueprint $table) 
            {
                $table ->integer('SC') -> nullable(); 
                $table ->integer('AM') -> nullable();
            .........
            });

The new table's name is now random. So far so good...

A new problem I have and I need your opinion is how to use $ppdf table inside a raw query.

For example the following gives me error:

DB::statement('alter table $ppdf add marktotext VARCHAR2(256)');

I have also tried with this

DB::statement('alter table '$ppdf' add marktotext VARCHAR2(256)');

etc with no success!

Any idea?

Jun
28
4 months ago
Activity icon

Replied to Forbidding Access To Database While Another User Requests Data From It

@TRAY2 - Hi Tray2!

Yes I have created tables in my controller using eloquent e.g.

Schema::create('table1', function (Blueprint $table) 
            {
                $table ->integer('id') -> nullable(); 
                $table ->string('description') -> nullable();
                $table ->float('mark') -> nullable();
            });

At the end of the code I clean my database dropping all intermediate tables. Although I have updated my code many times to use the less tables possible I couldn't avoid creating many of them on the whole.

After reading your advice I searched a little about temporary tables; Do you think unprepared method (DB::unprepared(DB::raw("query here"));) suits my case? https://laracasts.com/discuss/channels/laravel/how-to-implement-temporary-table

Activity icon

Replied to Forbidding Access To Database While Another User Requests Data From It

@SNAPEY - Users will not have personal ids. They just access the site page and fill some required data fields. I think of using the Str::random() to produce a random string each time a user submits form and use it as a token for each form submission. But I don't have an idea how to do it yet! What do you think?

use Illuminate\Support\Str;

$random = Str::random(10);
Activity icon

Started a new Conversation Forbidding Access To Database While Another User Requests Data From It

Hello fellows,

How can I exclude a user from accessing my database when another user has already requested data from it?

To be more specific for my case, when a user browses to my laravel site he/she fills a form and then submits it. This triggers an oracle db query and several tables are created in the background before producing and showing the final result on browser. If another user fills the same form with different initial data at the same time then the db temporary table data is messed and I get the laravel error page.

Is it possible to have the second (or third etc) concurrent form submission standing by the previous to be completed first? I think it's called the mutual exclusion problem.

PS: All this happens when using local xampp apache server and testing to open two laravel webpages and submitting data almost simultaneously. Will this be happening on a live server environment?

Jun
19
4 months ago
Activity icon

Replied to Global Variable In Controller

My solution (may not the be best but worked fine for me) was to store variable data into a database table and then request this data twice via the same query inside each function.

Activity icon

Replied to Help With Csv File Uploading...

The answer on the whole:

  1. Html form excerpt which asks user to input the .csv file:
<!DOCTYPE html>

<html>
<meta charset="UTF-8">
<head>


<title>test</title>

<style>
    section
    {
        text-align: justify;
        padding-top: 1%;
            padding-left: 35%;
            padding-right: 25%;        
    }
</style>
</head>
<body>

     <form method='post' enctype="multipart/form-data" action="/hard">
        
        {{csrf_field()}}

    <section>
        <label for="upload-file">select csv file</label>
            <input type="file" name="upload-file"">
        </div>
        <br>
        <input type="submit" value="Submit " name="submit">

        </section>
    .....................

  1. Controller function excerpt. The file is received and checked if it has the right extension (.csv) or it is empty. iconv is needed for correct greek language encoding (refer to my previous answer).
public function job(Request $p)
    {
        $nrg = DB::delete('delete from csv_data');  //clear csv_data table
                
        $upload = $p -> file('upload-file'); 

if ($upload==null)
                {
                    return view ('search_again');
                }
                else
                    {
                        $extension = $p->file('upload-file')->getClientOriginalExtension();
                        if ($extension !=='csv')
                            {
                                return view ('search_again');
                            }
                    }
        
            $filePath = $upload ->getRealPath();  //upload file path
        
            $file = fopen($filePath, 'r');


            $f_rownum = 0;

            if (($handle = fopen ( $filePath, 'r' )) !== FALSE) 
                {
                    while ( ($data = fgetcsv ( $handle, 1000, ',' )) !== FALSE )
                        {
                            $ac1=iconv("Windows-1253", "UTF-8", $data[0]);
                            $ac2=iconv("Windows-1253", "UTF-8", $data[1]);
                            $ac3=iconv("Windows-1253", "UTF-8", $data[2]);
                            ........
                            $ac72=iconv("Windows-1253", "UTF-8", $data[71]);
                            $ac73=iconv("Windows-1253", "UTF-8", $data[72]);

                            DB::table('csv_data')->insert([
                            'ac1'=> $ac1, 'ac2'=>$ac2,'ac3'=>$ac3, 'ac4'=>$ac4,
                            ..........,'ac73'=>$ac73]);
                            
$f_rownum++;
                            }
                            
                    fclose ( $handle );
            }

Jun
04
5 months ago
Activity icon

Replied to Query To Select Data From Database Table And Array

@NASH - I understand the risk. But is it possible to be done with Raw query?

Activity icon

Started a new Conversation Query To Select Data From Database Table And Array

How can I select data with raw query from data that exists both in database table and an array?

For example I want to store to $sc the result of the following query. The variable $cs is an array which has data from previous query execution.

$sc = DB::select(DB::Raw("select hrp1001_sc.rel_obj_id from hrp1001_sc, today_date where today_date.today <= hrp1001_sc.end_date and today_date.today >= hrp1001_sc.st_date and hrp1001_sc.object_id = $cs"));

May
31
5 months ago
Activity icon

Replied to Help With Csv File Uploading...

@DEVFREY - Hello again!

I had some issues with my csv numbers and had to update ',' to '.' in numbers (eg 7,5 to 7.5). I think that can be fixed somehow...

But my basic issue is how to pass the file from the form to my controller. The user should enter some other data along with the csv. The csv is uploaded only if it is placed inside public folder and in fact code does not take in mind my (desktop located) file. The code as it is takes file from public folder and successfully inserts it into my database. Could you give me your advice on this point please?

This is my form excerpt. At the bottom is where I ask user to upload file:

<body>

    <form method='post' enctype="multipart/form-data" action="/hard">

        {{csrf_field()}}

        <section>
        <br>
            <legend><i><b> Complete Data Below</b></i></legend>
        <br>
        </section>

        <section>   
        Choose program:
            <select name="sc" id="xaos">

            <optgroup label="postgraduates">
                @foreach($transport as $y)
                    <option value="{{$y->object_id}}">{{$y->object_name}}</option>
                @endforeach
            </optgroup>

            </select>
        </section>

    <br>

        <section>
        ID number: 
            <input name='am' type='number' min="1000000" max="1999999" required="" oninvalid="this.setCustomValidity('1000000 < Value < 1999999')">
        </section>

        <br>

        <section>
        Select Language:
            <select name="language" id="lang">
                    <option value="GR"> Greek</option>
                    <option value="EN"> English</option>
            </select>
        </section>
        <br>
        <section>
        <label for="upload-file">select csv file</label>
            <input type="file" name="upload-file"> 
        </div>
            <input type='submit' name='upload' value="Submit!">
        </section>

    </form>
    <br>
    <br>

</body>

And below is my controller excerpt which is supposed to receive file. The issue is with fopen function. How can it handle the file imported from the form above?

public function job(Request $p)
    {
        $a1 = $p -> get('sc');
        $a2 = $p -> get('am'); 
        $a3 = $p -> get('language'); 




    $f_rownum = 0;

    if (($handle = fopen ( 'MOCK_DATA.csv', 'r' )) !== FALSE) 

    {
        while ( ($data = fgetcsv ( $handle, 1000, ';' )) !== FALSE )
        {
            $ac1=$data[0];
            $ac2=iconv("Windows-1253", "UTF-8", $data[1]);
            $ac3=iconv("Windows-1253", "UTF-8", $data[2]);
            $ac4=iconv("Windows-1253", "UTF-8", $data[3]);
            $ac5=$data[4];

......
May
19
5 months ago
Activity icon

Replied to Help With Csv File Uploading...

@DEVFREY - I have found that replacing ',' delimiter with ';' at my code excerpt

if (($handle = fopen ( 'MOCK_DATA.csv', 'r' )) !== FALSE) 
        {
            while ( ($data = fgetcsv ( $handle, 0, ';' )) !== FALSE )
                dd($data);

and dd($data) fills all data. Just like below. The odd characters remain though.

array:73 [▼
  0 => "1040290"
  1 => b"ÐÁÐÁÄÇÌÇÔÑÉÏÕ, ÃÅÙÑÃÉÏÓ"
  2 => b"ÊÙÍÓÔÁÍÔÉÍÏÓ"
  3 => "234513"
  4 => "9198"
  5 => b"Áðüöïéôïò"
  6 => "5"
  7 => "STC_131"
  8 => b"ÄÉÁ×. ÓÕÍÈ. ÁÍÔÉÊ. ÐÏË.-ÌÅÓÙÍ ÓÅ Â. Ä."
  9 => "2014"
  10 => "20"
  11 => "2014"
  12 => "20"
  13 => "9,0"
  14 => ""
  15 => "2"
  16 => "1"
  17 => b"Ð"
  18 => b"ËÕ"
  19 => b"ÕÐÏ"
  20 => ""
  21 => "6,00"
  22 => "0,00"
  23 => b"ÐÌ"
  24 => "0,00"
  25 => "0,00"
  26 => b"ÄÌ"
  27 => "0,0"
  28 => "EG0STC_S2R1"
  29 => b"ËÕ 1ï ÅîÜìçíï Êïñìïý"
  30 => "EG0STC_SPEC"
  31 => b"Êáôåõèýíóåéò  ÅðéóôÞìçò &Ôå÷íïëïãßáò Ç/Õ"
  32 => "1"
  33 => "PR"
  34 => b"Äåßêôçò äåí Êáèïñßóôçêå"
  35 => b"Äåßêôçò äåí Êáèïñßóôçêå"
  36 => b"Äåßêôçò äåí Êáèïñßóôçêå"
  37 => b"Äåßêôçò äåí Êáèïñßóôçêå"
  38 => b"Ìç Ìåôáöåñüìåíï"
  39 => b"Ï÷é"
  40 => b"Åêðñüèåóìç"
  41 => "1"
  42 => "27/03/2015"
  43 => b"Ìç ÁôïìéêÞ Åñãáóßá"
  44 => "0"
  45 => ""
  46 => ""
  47 => "EMBK"
  48 => "00155D6E0B0B1ED4AAD6D796E8DA83E3"
  49 => "00155D6E0B0B1ED4AAD6D796E8DA63E3"
  50 => "00155D6E0B0B1ED4AAD6D796E8DA63E3"
  51 => "50091351"
  52 => "EG0_STC"
  53 => b"Ð.Ì.Ó. ÅðéóôÞìç &Ôå÷í ÇÕ (-2017)"
  54 => "50086330"
  55 => "50091396"
  56 => "0"
  57 => "50091374"
  58 => "50091355"
  59 => ""
  60 => ""
  61 => ""
  62 => "0"
  63 => "01/09/2014"
  64 => "15/02/2015"
  65 => "02/02/2015"
  66 => b"10:37:36 ðì"
  67 => "0"
  68 => ""
  69 => "2"
  70 => "50098572"
  71 => "00155D6E0B0B1ED4AAD6D796E8D8A3E3"
  72 => ""
]

But when I remove dd and try to run code on the whole the error changes to this:

Error Code : 942 Error Message : ORA-00942: table or view does not exist Position : 12 Statement : insert into "CSVDATA" ("AC1", "AC2", "AC3", "AC4", "AC5", "AC6", "AC7", "AC8", "AC9", "AC10", "AC11", "AC12", "AC13", "AC14", "AC15", "AC16", "AC17", "AC18", "AC19", "AC20", "AC21", "AC22", "AC23", "AC24", "AC25", "AC26", "AC27", "AC28", "AC29", "AC30", "AC31", "AC32", "AC33", "AC34", "AC35", "AC36", "AC37", "AC38", "AC39", "AC40", "AC41", "AC42", "AC43", "AC44", "AC45", "AC46", "AC47", "AC48", "AC49", "AC50", "AC51", "AC52", "AC53", "AC54", "AC55", "AC56", "AC57", "AC58", "AC59", "AC60", "AC61", "AC62", "AC63", "AC64", "AC65", "AC66", "AC67", "AC68", "AC69", "AC70", "AC71", "AC72", "AC73") values (:p0, :p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11, :p12, :p13, :p14, :p15, :p16, :p17, :p18, :p19, :p20, :p21, :p22, :p23, :p24, :p25, :p26, :p27, :p28, :p29, :p30, :p31, :p32, :p33, :p34, :p35, :p36, :p37, :p38, :p39, :p40, :p41, :p42, :p43, :p44, :p45, :p46, :p47, :p48, :p49, :p50, :p51, :p52, :p53, :p54, :p55, :p56, :p57, :p58, :p59, :p60, :p61, :p62, :p63, :p64, :p65, :p66, :p67, :p68, :p69, :p70, :p71, :p72) returning "ID" into :p73
Activity icon

Replied to Help With Csv File Uploading...

@DEVFREY - Never mind! Once again, thanks for helping!

I changed code as follows:

public function job(Request $p)
    {
        $a1 = $p -> get('sc');  //όνομα προγράμματος
        $a2 = $p -> get('am');  //αριθμός μητρώου φοιτητή
        $a3 = $p -> get('language');  //γλώσσα
        
        if (($handle = fopen ( 'MOCK_DATA.csv', 'r' )) !== FALSE) 
        {
            while ( ($data = fgetcsv ( $handle, 0, ',' )) !== FALSE )
                dd($data);

The result I'm getting is below. Why those strange characters appear? They represent greek language words in .csv.

array:8 [▼
  0 => b"1040290;ÐÁÐÁÄÇÌÇÔÑÉÏÕ"
  1 => b" ÃÅÙÑÃÉÏÓ;ÊÙÍÓÔÁÍÔÉÍÏÓ;234513;9198;Áðüöïéôïò;5;STC_131;ÄÉÁ×. ÓÕÍÈ. ÁÍÔÉÊ. ÐÏË.-ÌÅÓÙÍ ÓÅ Â. Ä.;2014;20;2014;20;9"
  2 => b"0;;2;1;Ð;ËÕ;ÕÐÏ;;6"
  3 => "00;0"
  4 => b"00;ÐÌ;0"
  5 => "00;0"
  6 => b"00;ÄÌ;0"
  7 => b"0;EG0STC_S2R1;ËÕ 1ï ÅîÜìçíï Êïñìïý;EG0STC_SPEC;Êáôåõèýíóåéò  ÅðéóôÞìçò &Ôå÷íïëïãßáò Ç/Õ;1;PR;Äåßêôçò äåí Êáèïñßóôçêå;Äåßêôçò äåí Êáèïñßóôçêå;Äåßêôçò äåí Êáèïñßóôçêå;Äåßêôçò äåí Êáèïñßóôçêå;Ìç Ìåôáöåñüìåíï;Ï÷é;Åêðñüèåóìç;1;27/03/2015;Ìç ÁôïìéêÞ Åñãáóßá;0;;;EMBK;00155D6E0B0B1ED4AAD6D796E8DA83E3;00155D6E0B0B1ED4AAD6D796E8DA63E3;00155D6E0B0B1ED4AAD6D796E8DA63E3;50091351;EG0_STC;Ð.Ì.Ó. ÅðéóôÞìç &Ôå÷í ÇÕ (-2017);50086330;50091396;0;50091374;50091355;;;;0;01/09/2014;15/02/2015;02/02/2015;10:37:36 ðì;0;;2;50098572;00155D6E0B0B1ED4AAD6D796E8D8A3E3; ◀"
]
Activity icon

Replied to Help With Csv File Uploading...

@DEVFREY - I altered code according your recommendation. I'm getting again "Undefined offset: 8". The error page now highlights code line.

$csv_data->{'ac'.($index + 1)} = $data[$index];

The code excerpt is this. What else could I check?

    public function job(Request $p)
    {
        $a1 = $p -> get('sc');  //όνομα προγράμματος
        $a2 = $p -> get('am');  //αριθμός μητρώου φοιτητή
        $a3 = $p -> get('language');  //γλώσσα
        
        if (($handle = fopen ( 'MOCK_DATA.csv', 'r' )) !== FALSE) 
        {
            while ( ($data = fgetcsv ( $handle, 0, ',' )) !== FALSE )
                {
                    {
                        $csv_data = new Csvdata ();
                        
                        foreach(range(0, 72) as $index) 
                        {
                            $csv_data->{'ac'.($index + 1)} = $data[$index];
                        }

                        
                        $csv_data->save ();
                    }
                    fclose ( $handle );
                }
                $finalData = $csv_data::all ();
                dd($finalData);

........................
Activity icon

Replied to Help With Csv File Uploading...

@DEVFREY - Hello @devfrey ... Thanks for replying! I have updated form according to your recommendation. The problems persist though. I'm trying to stick to this guide https://justlaravel.com/import-csv-data-store-database/?utm_source=learninglaravel.net but now I get Undefined offset: 8 error. What could that be?

To sum up, all my actions so far are:

I have run php artisan make:migration create_csv_data_table at cmd I created the table fields to database\migrations csv_data_table I have migrated this to database ( php artisan migrate) and the table csv_data is created into my oracle db I have also created the correspondig model (with php artisan make:model Csvdata)

And below some code excerpts relative to the issue:

  1. web.php
Route::get('/diploma', '[email protected]');
Route::post('/hard', '[email protected]');

Route::get('/p', '[email protected]');
Route::get('/export1','[email protected]')->name('export1.pdf');
  1. form:
<form method='post' enctype="multipart/form-data" action="/hard">

        {{csrf_field()}}

        <section>
        <br>
            <legend><i><b> Συμπλήρωση Στοιχείων Παραρτήματος Διπλώματος</b></i></legend>
        <br>
        </section>

        <section>   
        Επιλογή Προγράμματος Σπουδών:
            <select name="sc" id="xaos">

            <optgroup label="postgraduates">
                @foreach($transport as $y)
                    <option value="{{$y->object_id}}">{{$y->object_name}}</option>
                @endforeach
            </optgroup>

            </select>
        </section>

    <br>

        <section>
        Αριθμός Μητρώου Φοιτητή: 
            <input name='am' type='number' min="1000000" max="1999999" required="" oninvalid="this.setCustomValidity('1000000 < Τιμή < 1999999')">
        </section>

        <br>

        <section>
        Επιλογή Γλώσσας:
            <select name="language" id="lang">
                    <option value="GR"> Greek</option>
                    <option value="EN"> English</option>
            </select>
        </section>

        <br>

        <section>
        <label for="upload-file">select csv file</label>
            <input type="file" name="upload-file" class="form-control">
        </div>
        <input class="btn btn-success" type="submit" value="Upload " name="submit">

        <section>
        <br>
            <input type='submit' value="Submit!">
        </section>

    </form>
  1. migrations file class:
class CreateCsvDataTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('csv_data', function (Blueprint $table) 
        {
            $table->integer('ac1')-> nullable();
            $table->string('ac2')-> nullable();
            $table->string('ac3')-> nullable();
            $table->integer('ac4')-> nullable();
            $table->integer('ac5')-> nullable();
            $table->string('ac6')-> nullable();
            $table->integer('ac7')-> nullable();
            $table->string('ac8')-> nullable();
            $table->string('ac9')-> nullable();
            $table->integer('ac10')-> nullable();
            $table->integer('ac11')-> nullable();
            $table->integer('ac12')-> nullable();
            $table->integer('ac13')-> nullable();
            $table->float('ac14')-> nullable();
            $table->integer('ac15')-> nullable();
            $table->integer('ac16')-> nullable();
            $table->integer('ac17')-> nullable();
            $table->string('ac18')-> nullable();
            $table->string('ac19')-> nullable();
            $table->string('ac20')-> nullable();
            $table->string('ac21')-> nullable();
            $table->integer('ac22')-> nullable();
            $table->float('ac23')-> nullable();
            $table->string('ac24')-> nullable();
            $table->float('ac25')-> nullable();
            $table->float('ac26')-> nullable();
            $table->string('ac27')-> nullable();
            $table->float('ac28')-> nullable();
            $table->string('ac29')-> nullable();
            $table->string('ac30')-> nullable();
            $table->string('ac31')-> nullable();
            $table->string('ac32')-> nullable();
            $table->integer('ac33')-> nullable();
            $table->string('ac34')-> nullable();
            $table->string('ac35')-> nullable();
            $table->string('ac36')-> nullable();
            $table->string('ac37')-> nullable();
            $table->string('ac38')-> nullable();
            $table->string('ac39')-> nullable();
            $table->string('ac40')-> nullable();
            $table->string('ac41')-> nullable();
            $table->integer('ac42')-> nullable();
            $table->date('ac43')-> nullable();
            $table->string('ac44')-> nullable();
            $table->string('ac45')-> nullable();
            $table->string('ac46')-> nullable();
            $table->string('ac47')-> nullable();
            $table->string('ac48')-> nullable();
            $table->string('ac49')-> nullable();
            $table->string('ac50')-> nullable();
            $table->string('ac51')-> nullable();
            $table->string('ac52')-> nullable();
            $table->string('ac53')-> nullable();
            $table->string('ac54')-> nullable();
            $table->integer('ac55')-> nullable();
            $table->integer('ac56')-> nullable();
            $table->integer('ac57')-> nullable();
            $table->integer('ac58')-> nullable();
            $table->integer('ac59')-> nullable();
            $table->string('ac60')-> nullable();
            $table->string('ac61')-> nullable();
            $table->string('ac62')-> nullable();
            $table->integer('ac63')-> nullable();
            $table->date('ac64')-> nullable();
            $table->date('ac65')-> nullable();
            $table->date('ac66')-> nullable();
            $table->string('ac67')-> nullable();
            $table->integer('ac68')-> nullable();
            $table->string('ac69')-> nullable();
            $table->integer('ac70')-> nullable();
            $table->integer('ac71')-> nullable();
            $table->string('ac72')-> nullable();
            $table->string('ac73')-> nullable();

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('csv_data');
    }
}
  1. Controller excerpt (when pressing upload at my form I get Undefined offset: 8 error and line $csv_data->ac9 =$data [8]; is marked)
public function job(Request $p)
    {
        $a1 = $p -> get('sc');  //όνομα προγράμματος
        $a2 = $p -> get('am');  //αριθμός μητρώου φοιτητή
        $a3 = $p -> get('language');  //γλώσσα

        if (($handle = fopen ( 'MOCK_DATA.csv', 'r' )) !== FALSE) 
        {
            while ( ($data = fgetcsv ( $handle, 1000, ',' )) !== FALSE )
                {
                    {
                        $csv_data = new Csvdata ();
                        $csv_data->ac1  =$data [0];
                        $csv_data->ac2  =$data [1];
                        $csv_data->ac3  =$data [2];
                        $csv_data->ac4  =$data [3];
                        $csv_data->ac5  =$data [4];
                        $csv_data->ac6  =$data [5];
                        $csv_data->ac7  =$data [6];
                        $csv_data->ac8  =$data [7];
                        $csv_data->ac9  =$data [8];
                        $csv_data->ac10 =$data [9];
                        $csv_data->ac11 =$data [10];
                        $csv_data->ac12 =$data [11];
                        $csv_data->ac13 =$data [12];
                        $csv_data->ac14 =$data [13];
                        $csv_data->ac15 =$data [14];
                        $csv_data->ac16 =$data [15];
                        $csv_data->ac17 =$data [16];
                        $csv_data->ac18 =$data [17];
                        $csv_data->ac19 =$data [18];
                        $csv_data->ac20 =$data [19];
                        $csv_data->ac21 =$data [20];
                        $csv_data->ac22 =$data [21];
                        $csv_data->ac23 =$data [22];
                        $csv_data->ac24 =$data [23];
                        $csv_data->ac25 =$data [24];
                        $csv_data->ac26 =$data [25];
                        $csv_data->ac27 =$data [26];
                        $csv_data->ac28 =$data [27];
                        $csv_data->ac29 =$data [28];
                        $csv_data->ac30 =$data [29];
                        $csv_data->ac31 =$data [30];
                        $csv_data->ac32 =$data [31];
                        $csv_data->ac33 =$data [32];
                        $csv_data->ac34 =$data [33];
                        $csv_data->ac35 =$data [34];
                        $csv_data->ac36 =$data [35];
                        $csv_data->ac37 =$data [36];
                        $csv_data->ac38 =$data [37];
                        $csv_data->ac39 =$data [38];
                        $csv_data->ac40 =$data [39];
                        $csv_data->ac41 =$data [40];
                        $csv_data->ac42 =$data [41];
                        $csv_data->ac43 =$data [42];
                        $csv_data->ac44 =$data [43];
                        $csv_data->ac45 =$data [44];
                        $csv_data->ac46 =$data [45];
                        $csv_data->ac47 =$data [46];
                        $csv_data->ac48 =$data [47];
                        $csv_data->ac49 =$data [48];
                        $csv_data->ac50 =$data [49];
                        $csv_data->ac51 =$data [50];
                        $csv_data->ac52 =$data [51];
                        $csv_data->ac53 =$data [52];
                        $csv_data->ac54 =$data [53];
                        $csv_data->ac55 =$data [54];
                        $csv_data->ac56 =$data [55];
                        $csv_data->ac57 =$data [56];
                        $csv_data->ac58 =$data [57];
                        $csv_data->ac59 =$data [58];
                        $csv_data->ac60 =$data [59];
                        $csv_data->ac61 =$data [60];
                        $csv_data->ac62 =$data [61];
                        $csv_data->ac63 =$data [62];
                        $csv_data->ac64 =$data [63];
                        $csv_data->ac65 =$data [64];
                        $csv_data->ac66 =$data [65];
                        $csv_data->ac67 =$data [66];
                        $csv_data->ac68 =$data [67];
                        $csv_data->ac69 =$data [68];
                        $csv_data->ac70 =$data [69];
                        $csv_data->ac71 =$data [70];
                        $csv_data->ac72 =$data [71];
                        $csv_data->ac73 =$data [72];

                        $csv_data->save ();
                    }
                    fclose ( $handle );
                }
                $finalData = $csv_data::all ();
                dd($finalData);
May
18
5 months ago
Activity icon

Started a new Conversation Help With Csv File Uploading...

Hello guys. I'm trying to upload a .csv file to my (oracle) database. In fact the end user should insert this file along with other data. After submitting, a pdf file should be created.

I have created class CreateCsvDataTable (php migrate) with schema csv_data and the table csv_data exists in my oracle. It should be populated without headers.

My trouble is with csv uploading (please have a look at point (3)). When giving dd($header); I get this error:

Call to a member function getRealPath() on null

Could you please assist?

(1) My web.php routes file is the following:

Route::get('/diploma', '[email protected]');
Route::post('/hard', '[email protected]');

Route::get('/p', '[email protected]');
Route::get('/export1','[email protected]')->name('export1.pdf');

(2) The form code (blade excerpt) with data requested is this:

    <form method='post' action="/hard">
    
        {{csrf_field()}}
        

        
        <section>   
        Choose program:
            <select name="sc" id="xaos">
        
            <optgroup label="postgraduates">
                @foreach($transport as $y)
                    <option value="{{$y->object_id}}">{{$y->object_name}}</option>
                @endforeach
            </optgroup>
        
            </select>
        </section>
    
    <br>

        <section>
        AM: 
            <input name='am' type='number' min="1000000" max="1999999" required="" oninvalid="this.setCustomValidity('1000000 < Value < 1999999')">
        </section>
        
        <br>
        
        <section>
        Select language:
            <select name="language" id="lang">
                    <option value="GR"> Greek</option>
                    <option value="EN"> English</option>
            </select>
        </section>
        
        <br>
        
        <section>
        <label for="upload-file">select csv file</label>
            <input type="file" name="upload-file" class="form-control">
        </div>
        <input class="btn btn-success" type="submit" value="Upload " name="submit">

        <section>
        <br>
            <input type='submit' value="Submit!">
        </section>
        
    </form>

(3) And the PdfController.php excerpt regarding form input data get is this:

public function job(Request $p)
    {
        $a1 = $p -> get('sc');  //works!
        $a2 = $p -> get('am');  //works!
        $a3 = $p -> get('language');  //works!
        
        //get csv file                          
        $upload = $p -> file('upload-file');
        $filePath = $upload ->getRealPath(); --> HELP NEEDED HERE!!
        
        //open and read file
        $file = fopen($filePath, 'r');
        $header = fgetcsv($file); //I want to insert data without header
        
        dd($header);
May
15
5 months ago
Activity icon

Replied to Date Format In Laravel Controller

@CORCRONJE - That's it! It worked!

I know it returns string. I may alter that later but it's on purpose for now.

Thanks a lot!

Activity icon

Replied to Date Format In Laravel Controller

@corcronje

Thanks for helping me!

My table ( 1x5) is this:

first_name last_name id date_of_birth city Dimitra Ioan 312312 19/04/95 New York

  1. Controller (only consider 'mydate => $d):

My query is this

$d = DB::table('student_data')->value('date_of_birth');

//code blalba...

return view('exagogi', ['epwnymo' => $a, 'onoma' => $b, 'arithmos' => $c, 'mydate => $d, 'xwra' => $e]);
  1. exagogi.blade
<!DOCTYPE html>


<head>

....

</head>
<body>

....

1.4 &nbsp;Date of Birth (day/month/year):&nbsp;{{$mydate}}  <!-- the result here is "1995-04-19 00:00:00" -->

....
</body>
<html>
Activity icon

Replied to Date Format In Laravel Controller

Hi @corcronje and @nakov

unfortunately I get errors. I tried this at my blade

{{ \Carbon\Carbon::parse($mydate->endda)->format('d/m/Y')}}

but also fails...

Activity icon

Replied to Date Format In Laravel Controller

@CORCRONJE - Hi @corcronje

I tested it but this returns error:

Call to a member function format() on string

I also got the same error when I alter my code as

$d->format('dd/mm/Y');
dd($d);

In fact I want to pass this date data to a blade. At least, is it possible to alter date format in blade?

Activity icon

Started a new Conversation Date Format In Laravel Controller

Hello guys.

I retrieve some data from my database student_data table. The date of birth inside the table is 19/04/95. (The format is dd/mm/yy). The data is retrieved with this command:

$d = DB::table('student_data')->value('date_of_birth');

But testing with dd($d) gives me this result:

"1995-04-19 00:00:00"

How can I alter dd($d) result to show date as follows?

19/04/1995

Thanks in advance.