app/Http/Controllers/admin/ConfigController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
      $data = $request -> except('_token');
       if($request -> hasFile('logo')){
            $profile = $request -> file('logo');
            $ext = $profile->getClientOriginalExtension();
            $temp_name = str_random(20);
            $filename =  $temp_name.'.'.$ext;
            $dirname = date('Ymd',time());
            $res = $profile -> move('./uploads/logo/'.$dirname,$filename);
            $fileadd = ('/uploads/logo/'.$dirname.'/'.$filename);
            $data['logo'] = $fileadd;
       }
       $config = Config::find('1');
       $config -> net_name = $data['net_name'];
       $config -> net_keyword = $data['net_keyword'];
       $config -> copyright= $data['copyright'];
       $config -> onoff= $data['onoff'];
       $config -> logo= $data['logo'];
       $config -> net_phone= $data['net_phone'];
       $res = $config -> save();
        if($res){
            return redirect(url('/admin/config')) -> with('success','网站配置成功');
        }else{
            return back() -> with('error','错误!!!');
        }
    }
public function store ( Request $ request ) { $ data = $ request -> except ( '_token' ) ; if ( $ request -> hasFile ( 'logo' ) ) { $ profile = $ request -> file ( 'logo' ) ; $ ext = $ profile -> getClientOriginalExtension ( ) ; $ temp_name = str_random ( 20 ) ; $ filename = $ temp_name . '.' . $ ext ; $ dirname = date ( 'Ymd' , time ( ) ) ; $ res = $ profile -> move ( './uploads/logo/' . $ dirname , $ filename ) ; $ fileadd = ( '/uploads/logo/' . $ dirname . '/' . $ filename ) ; $ data [ 'logo' ] = $ fileadd ; } $ config = Config :: find ( '1' ) ; $ config -> net_name = $ data [ 'net_name' ] ; $ config -> net_keyword = $ data [ 'net_keyword' ] ; $ config -> copyright = $ data [ 'copyright' ] ; $ config -> onoff = $ data [ 'onoff' ] ; $ config -> logo = $ data [ 'logo' ] ; $ config -> net_phone = $ data [ 'net_phone' ] ; $ res = $ config -> save ( ) ; if ( $ res ) { return redirect ( url ( '/admin/config' ) ) -> with ( 'success' , '网站配置成功'); } else { return back ( ) -> with ( 'error' , '错误!!!'); } }
Store a newly created resource in storage.
Store a newly created resource in storage .
//接收修改数据 //dd($data); //保存图像 // 使用request 创建文件上传对象 // 获取文件后缀名 // 处理文件名称 // 保存文件 //如果有没文件上传,会被重新赋值保存 //存储 //处理返回值