Laravel 5.2在DB表中存储数据库

时间:2016-11-11 08:17:25

标签: php mysql database laravel laravel-5.2

我是Laravel的新人,所以任何人都可以帮助我 我想将数据存储在我的数据库中,我不知道我做的是否正确。抱歉是个菜鸟。

这是我的PaypalController

         <?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Input;

use Illuminate\Support\Facades\Validator;

use Illuminate\Support\Facades\Redirect;

use Illuminate\Support\Facades\Request;

use Illuminate\Support\Facades\Session;

use Illuminate\Support\Facades\Auth;

use Illuminate\Support\Facades\DB;

use Illuminate\Mail\Mailer;

use App\Maintenance;

use App\Time_tracker;


class PaypalController extends Controller {

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

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Http\Response
 */

 public function index() {

 return view('paypal'); 

 }

 public function success() {
     $price = \Session::get('value_price');
 $value = $price;
 if($value == '465'){

         $paid = 'paid';
     DB::table('users')->insert([
     ['user_id' => $id],
     ['paid' => $paid]
     ]);
     $user_id = Auth::user()->id;
     $user = maintenance::find($id);
     $current_hour = $nerd->hour;
     $purchase_time = $purchase_time + 15;
     $current_hour = $current_hour + $purchase_time;

     $user = new Time_tracker;
         $user->hoursT = $current_hour;
     $user->paid = $paid;
         $user->date = $status;
         $user->save();




 }elseif($value == '700'){

    //   $paid = paid;
     DB::table('users')->insert([
     ['user_id' => $id],
     ['paid' => $paid]
     ]);
     $user_id = Auth::user()->id;
     $user = maintenance::find($id);
     $current_hour = $nerd->hour;
     $purchase_time = $purchase_time + 25;
     $current_hour = $current_hour + $purchase_time;

     $user = new Time_tracker;
         $user->hoursT = $current_hour;
     $user->paid = $paid;
         $user->date = $status;
         $user->save();


  }elseif($value == '1300'){

         $paid = paid;
     DB::table('users')->insert([
     ['user_id' => $id],
     ['paid' => $paid]
     ]);
     $user_id = Auth::user()->id;
     $user = maintenance::find($id);
     $current_hour = $nerd->hour;
     $purchase_time = $purchase_time + 50;
     $current_hour = $current_hour + $purchase_time;

     $user = new Time_tracker;
         $user->hoursT = $current_hour;
     $user->paid = $paid;
         $user->date = $status;
         $user->save();



   }


   return view('success');  

   }


   public function failed() {

     return view('failed'); 

 }


}

这是我的MaintenanceformController

    <?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Input;

use Illuminate\Support\Facades\Validator;

use Illuminate\Support\Facades\Redirect;

use Illuminate\Support\Facades\Request;

use Illuminate\Support\Facades\Session;

use Illuminate\Support\Facades\DB;

use Illuminate\Support\Facades\Auth;

use Illuminate\Mail\Mailer;

use App\Maintenance;

use App\Apply;

class MaintenanceformController extends Controller { 

  public function index() {
     $TownResults = DB::table('apply')->where('user', '=', Auth::user()->id)->get(); 
     return view('maintenanceform')->with('town_list', $TownResults);
  }

  public function multiple_upload() {

     $files = Input::file('images');
     $tasknumber = Input::get('tasknumber');
     $ordernumber = Input::get('ordernumber');
     $status = Input::get('status');
     $directions = Input::get('directions');
     $comments = Input::get('comments');
         $user_id = Auth::user()->id;
         $designation = Input::get('designation');

    $file_count = count($files);

    // start count how many uploaded

    $uploadcount = 0;


    foreach($files as $file) {

      $rules = array('file' => 'required'); //'required|mimes:png,gif,jpeg,txt,pdf,doc'

      $validator = Validator::make(array('file'=> $file), $rules);

      if($validator->passes()){

        $destinationPath = 'uploads/'.$tasknumber.'';

        $filename = ''.$tasknumber.'_'.$file->getClientOriginalName().'';

        $upload_success = $file->move($destinationPath, $filename);

        $uploadcount ++;



      }

    }

    $user = new Maintenance;

    $user->tasknumber = $tasknumber;
    $user->ordernumber = $ordernumber;
    $user->status = $status;
    $user->directions = $directions;
    $user->comments = $comments;
    $user->user_id = $user_id;
    $user->designation = $designation;

    $user->save();



   if($uploadcount == $file_count){

      Session::flash('success', 'Upload successfully'); 

      return Redirect::to('maintenance');

    } 

    else {

      return Redirect::to('maintenance')->withInput()->withErrors($validator);

    }


  }
}

我想在DB表中保存user_id,hoursT,paid和purchase_time。谁能帮帮我吗。 :)

0 个答案:

没有答案